...

Source file src/github.com/MicahParks/keyfunc/v2/oct.go

Documentation: github.com/MicahParks/keyfunc/v2

     1  package keyfunc
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  const (
     8  	// ktyOct is the key type (kty) in the JWT header for oct.
     9  	ktyOct = "oct"
    10  )
    11  
    12  // Oct parses a jsonWebKey and turns it into a raw byte slice (octet). This includes HMAC keys.
    13  func (j *jsonWebKey) Oct() (publicKey []byte, err error) {
    14  	if j.K == "" {
    15  		return nil, fmt.Errorf("%w: %s", ErrMissingAssets, ktyOct)
    16  	}
    17  
    18  	// Decode the octet key from Base64.
    19  	//
    20  	// According to RFC 7517, this is Base64 URL bytes.
    21  	// https://datatracker.ietf.org/doc/html/rfc7517#section-1.1
    22  	publicKey, err = base64urlTrailingPadding(j.K)
    23  	if err != nil {
    24  		return nil, err
    25  	}
    26  
    27  	return publicKey, nil
    28  }
    29  

View as plain text