...

Source file src/github.com/lestrrat-go/jwx/jwa/key_encryption_gen.go

Documentation: github.com/lestrrat-go/jwx/jwa

     1  // this file was auto-generated by internal/cmd/gentypes/main.go: DO NOT EDIT
     2  
     3  package jwa
     4  
     5  import (
     6  	"fmt"
     7  	"sort"
     8  	"sync"
     9  
    10  	"github.com/pkg/errors"
    11  )
    12  
    13  // KeyEncryptionAlgorithm represents the various encryption algorithms as described in https://tools.ietf.org/html/rfc7518#section-4.1
    14  type KeyEncryptionAlgorithm string
    15  
    16  // Supported values for KeyEncryptionAlgorithm
    17  const (
    18  	A128GCMKW          KeyEncryptionAlgorithm = "A128GCMKW"          // AES-GCM key wrap (128)
    19  	A128KW             KeyEncryptionAlgorithm = "A128KW"             // AES key wrap (128)
    20  	A192GCMKW          KeyEncryptionAlgorithm = "A192GCMKW"          // AES-GCM key wrap (192)
    21  	A192KW             KeyEncryptionAlgorithm = "A192KW"             // AES key wrap (192)
    22  	A256GCMKW          KeyEncryptionAlgorithm = "A256GCMKW"          // AES-GCM key wrap (256)
    23  	A256KW             KeyEncryptionAlgorithm = "A256KW"             // AES key wrap (256)
    24  	DIRECT             KeyEncryptionAlgorithm = "dir"                // Direct encryption
    25  	ECDH_ES            KeyEncryptionAlgorithm = "ECDH-ES"            // ECDH-ES
    26  	ECDH_ES_A128KW     KeyEncryptionAlgorithm = "ECDH-ES+A128KW"     // ECDH-ES + AES key wrap (128)
    27  	ECDH_ES_A192KW     KeyEncryptionAlgorithm = "ECDH-ES+A192KW"     // ECDH-ES + AES key wrap (192)
    28  	ECDH_ES_A256KW     KeyEncryptionAlgorithm = "ECDH-ES+A256KW"     // ECDH-ES + AES key wrap (256)
    29  	PBES2_HS256_A128KW KeyEncryptionAlgorithm = "PBES2-HS256+A128KW" // PBES2 + HMAC-SHA256 + AES key wrap (128)
    30  	PBES2_HS384_A192KW KeyEncryptionAlgorithm = "PBES2-HS384+A192KW" // PBES2 + HMAC-SHA384 + AES key wrap (192)
    31  	PBES2_HS512_A256KW KeyEncryptionAlgorithm = "PBES2-HS512+A256KW" // PBES2 + HMAC-SHA512 + AES key wrap (256)
    32  	RSA1_5             KeyEncryptionAlgorithm = "RSA1_5"             // RSA-PKCS1v1.5
    33  	RSA_OAEP           KeyEncryptionAlgorithm = "RSA-OAEP"           // RSA-OAEP-SHA1
    34  	RSA_OAEP_256       KeyEncryptionAlgorithm = "RSA-OAEP-256"       // RSA-OAEP-SHA256
    35  )
    36  
    37  var allKeyEncryptionAlgorithms = map[KeyEncryptionAlgorithm]struct{}{
    38  	A128GCMKW:          {},
    39  	A128KW:             {},
    40  	A192GCMKW:          {},
    41  	A192KW:             {},
    42  	A256GCMKW:          {},
    43  	A256KW:             {},
    44  	DIRECT:             {},
    45  	ECDH_ES:            {},
    46  	ECDH_ES_A128KW:     {},
    47  	ECDH_ES_A192KW:     {},
    48  	ECDH_ES_A256KW:     {},
    49  	PBES2_HS256_A128KW: {},
    50  	PBES2_HS384_A192KW: {},
    51  	PBES2_HS512_A256KW: {},
    52  	RSA1_5:             {},
    53  	RSA_OAEP:           {},
    54  	RSA_OAEP_256:       {},
    55  }
    56  
    57  var listKeyEncryptionAlgorithmOnce sync.Once
    58  var listKeyEncryptionAlgorithm []KeyEncryptionAlgorithm
    59  
    60  // KeyEncryptionAlgorithms returns a list of all available values for KeyEncryptionAlgorithm
    61  func KeyEncryptionAlgorithms() []KeyEncryptionAlgorithm {
    62  	listKeyEncryptionAlgorithmOnce.Do(func() {
    63  		listKeyEncryptionAlgorithm = make([]KeyEncryptionAlgorithm, 0, len(allKeyEncryptionAlgorithms))
    64  		for v := range allKeyEncryptionAlgorithms {
    65  			listKeyEncryptionAlgorithm = append(listKeyEncryptionAlgorithm, v)
    66  		}
    67  		sort.Slice(listKeyEncryptionAlgorithm, func(i, j int) bool {
    68  			return string(listKeyEncryptionAlgorithm[i]) < string(listKeyEncryptionAlgorithm[j])
    69  		})
    70  	})
    71  	return listKeyEncryptionAlgorithm
    72  }
    73  
    74  // Accept is used when conversion from values given by
    75  // outside sources (such as JSON payloads) is required
    76  func (v *KeyEncryptionAlgorithm) Accept(value interface{}) error {
    77  	var tmp KeyEncryptionAlgorithm
    78  	if x, ok := value.(KeyEncryptionAlgorithm); ok {
    79  		tmp = x
    80  	} else {
    81  		var s string
    82  		switch x := value.(type) {
    83  		case fmt.Stringer:
    84  			s = x.String()
    85  		case string:
    86  			s = x
    87  		default:
    88  			return errors.Errorf(`invalid type for jwa.KeyEncryptionAlgorithm: %T`, value)
    89  		}
    90  		tmp = KeyEncryptionAlgorithm(s)
    91  	}
    92  	if _, ok := allKeyEncryptionAlgorithms[tmp]; !ok {
    93  		return errors.Errorf(`invalid jwa.KeyEncryptionAlgorithm value`)
    94  	}
    95  
    96  	*v = tmp
    97  	return nil
    98  }
    99  
   100  // String returns the string representation of a KeyEncryptionAlgorithm
   101  func (v KeyEncryptionAlgorithm) String() string {
   102  	return string(v)
   103  }
   104  
   105  // IsSymmetric returns true if the algorithm is a symmetric type
   106  func (v KeyEncryptionAlgorithm) IsSymmetric() bool {
   107  	switch v {
   108  	case A128GCMKW, A128KW, A192GCMKW, A192KW, A256GCMKW, A256KW, DIRECT, PBES2_HS256_A128KW, PBES2_HS384_A192KW, PBES2_HS512_A256KW:
   109  		return true
   110  	}
   111  	return false
   112  }
   113  

View as plain text