From bb5863e15e41a126474cff7d3119e208d39a5aef Mon Sep 17 00:00:00 2001 From: Anant Prakash Date: Tue, 22 May 2018 11:59:32 +0530 Subject: [PATCH] Remove copyright, trim empty lines --- .../dendrite/clientapi/auth/tokens/tokens.go | 13 +++---------- .../dendrite/clientapi/auth/tokens/tokens_test.go | 5 ----- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/tokens/tokens.go b/src/github.com/matrix-org/dendrite/clientapi/auth/tokens/tokens.go index 51dedf6aa..abcb59fd3 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/tokens/tokens.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/tokens/tokens.go @@ -1,5 +1,3 @@ -// Copyright 2018 New Vector Ltd -// // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at @@ -46,13 +44,11 @@ type TokenOptions struct { // GenerateLoginToken generates a short term login token to be used as // token authentication ("m.login.token") func GenerateLoginToken(op TokenOptions) (string, error) { - if !isValidTokenOptions(op) { return "", errors.New("The given TokenOptions is invalid") } mac, err := generateBaseMacaroon(op.ServerPrivateKey, op.ServerName, op.UserID) - if err != nil { return "", err } @@ -63,12 +59,11 @@ func GenerateLoginToken(op TokenOptions) (string, error) { now := time.Now().Second() expiryCaveat := TimePrefix + strconv.Itoa(now+op.Duration) err = mac.AddFirstPartyCaveat([]byte(expiryCaveat)) - if err != nil { return "", macaroonError(err) } - urlSafeEncode, err := SerializeMacaroon(*mac) + urlSafeEncode, err := SerializeMacaroon(*mac) if err != nil { return "", macaroonError(err) } @@ -115,12 +110,11 @@ func macaroonError(err error) error { // returns it's base64 encoded string, URL safe, which can be sent via web, email, etc. func SerializeMacaroon(m macaroon.Macaroon) (string, error) { bin, err := m.MarshalBinary() - if err != nil { return "", err } - urlSafeEncode := base64.RawURLEncoding.EncodeToString(bin) + urlSafeEncode := base64.RawURLEncoding.EncodeToString(bin) return urlSafeEncode, nil } @@ -129,11 +123,10 @@ func SerializeMacaroon(m macaroon.Macaroon) (string, error) { func DeSerializeMacaroon(urlSafeEncode string) (macaroon.Macaroon, error) { var mac macaroon.Macaroon bin, err := base64.RawURLEncoding.DecodeString(urlSafeEncode) - if err != nil { return mac, err } - err = mac.UnmarshalBinary(bin) + err = mac.UnmarshalBinary(bin) return mac, err } diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/tokens/tokens_test.go b/src/github.com/matrix-org/dendrite/clientapi/auth/tokens/tokens_test.go index 00a42475f..4c9438df5 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/tokens/tokens_test.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/tokens/tokens_test.go @@ -41,7 +41,6 @@ var ( func TestGenerateLoginToken(t *testing.T) { // Test valid _, err := GenerateLoginToken(validTokenOp) - if err != nil { t.Errorf("Token generation failed for valid TokenOptions with err: %s", err.Error()) } @@ -49,7 +48,6 @@ func TestGenerateLoginToken(t *testing.T) { // Test invalids for missing, invalidTokenOp := range invalidTokenOps { _, err := GenerateLoginToken(invalidTokenOp) - if err == nil { t.Errorf("Token generation should fail for TokenOptions with missing %s", missing) } @@ -62,19 +60,16 @@ func serializationTestError(err error) string { func TestSerialization(t *testing.T) { fakeToken, err := GenerateLoginToken(validTokenOp) - if err != nil { t.Errorf(serializationTestError(err)) } fakeMacaroon, err := DeSerializeMacaroon(fakeToken) - if err != nil { t.Errorf(serializationTestError(err)) } sameFakeToken, err := SerializeMacaroon(fakeMacaroon) - if err != nil { t.Errorf(serializationTestError(err)) }