github.com/hyperledger/aries-framework-go@v0.3.2/pkg/doc/verifiable/jwt_unsecured.go (about) 1 /* 2 Copyright SecureKey Technologies Inc. All Rights Reserved. 3 SPDX-License-Identifier: Apache-2.0 4 */ 5 6 package verifiable 7 8 import ( 9 "fmt" 10 11 "github.com/hyperledger/aries-framework-go/pkg/doc/jose" 12 "github.com/hyperledger/aries-framework-go/pkg/doc/jwt" 13 ) 14 15 func marshalUnsecuredJWT(headers jose.Headers, claims interface{}) (string, error) { 16 token, err := jwt.NewUnsecured(claims, headers) 17 if err != nil { 18 return "", fmt.Errorf("marshal unsecured JWT: %w", err) 19 } 20 21 return token.Serialize(false) 22 } 23 24 func unmarshalUnsecuredJWT(rawJWT string, claims interface{}) error { 25 token, _, err := jwt.Parse(rawJWT, jwt.WithSignatureVerifier(jwt.UnsecuredJWTVerifier())) 26 if err != nil { 27 return fmt.Errorf("unmarshal unsecured JWT: %w", err) 28 } 29 30 return token.DecodeClaims(claims) 31 }