From f864fd905d9b50fb8790e8b5d5cb598d05cc587b Mon Sep 17 00:00:00 2001 From: Shreya Vissamsetti Date: Thu, 28 Mar 2024 09:48:26 -0700 Subject: [PATCH] Minor uma v1 fixes --- uma/protocol/pub_key_response.go | 14 +++++++++++--- uma/version.go | 17 ++--------------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/uma/protocol/pub_key_response.go b/uma/protocol/pub_key_response.go index 13df0e7..88e9758 100644 --- a/uma/protocol/pub_key_response.go +++ b/uma/protocol/pub_key_response.go @@ -31,7 +31,11 @@ func (r *PubKeyResponse) SigningPubKey() ([]byte, error) { } return publicKey.SerializeUncompressed(), nil } else if r.SigningPubKeyHex != nil { - return hex.DecodeString(*r.SigningPubKeyHex) + publicKey, err := hex.DecodeString(*r.SigningPubKeyHex) + if err != nil { + return nil, err + } + return publicKey, nil } else { return nil, errors.New("signingPubKeyHex is nil") } @@ -44,8 +48,12 @@ func (r *PubKeyResponse) EncryptionPubKey() ([]byte, error) { return nil, err } return publicKey.SerializeUncompressed(), nil - } else if r.EncryptionPubKeyHex == nil { - return hex.DecodeString(*r.EncryptionPubKeyHex) + } else if r.EncryptionPubKeyHex != nil { + publicKey, err := hex.DecodeString(*r.EncryptionPubKeyHex) + if err != nil { + return nil, err + } + return publicKey, nil } else { return nil, errors.New("encryptionPubKeyHex is nil") } diff --git a/uma/version.go b/uma/version.go index bbed862..3098246 100644 --- a/uma/version.go +++ b/uma/version.go @@ -3,8 +3,6 @@ package uma import ( "encoding/json" "fmt" - "strconv" - "strings" ) const MAJOR_VERSION = 1 @@ -24,23 +22,12 @@ func (e UnsupportedVersionError) Error() string { } func GetSupportedMajorVersionsFromErrorResponseBody(errorResponseBody []byte) ([]int, error) { - responseJson := make(map[string]string) + var responseJson UnsupportedVersionError err := json.Unmarshal(errorResponseBody, &responseJson) if err != nil { return nil, err } - - vasp2SupportedMajorVersions := responseJson["supportedMajorVersions"] - vasp2SupportedMajorVersionsList := strings.Split(vasp2SupportedMajorVersions, ",") - vasp2SupportedMajorVersionsIntList := make([]int, len(vasp2SupportedMajorVersionsList)) - for i, version := range vasp2SupportedMajorVersionsList { - versionInt, err := strconv.Atoi(version) - if err != nil { - return nil, err - } - vasp2SupportedMajorVersionsIntList[i] = versionInt - } - return vasp2SupportedMajorVersionsIntList, nil + return responseJson.SupportedMajorVersions, nil } func getSupportedMajorVersionsMap() map[int]struct{} {