...

Source file src/github.com/lestrrat-go/jwx/jwa/content_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  // ContentEncryptionAlgorithm represents the various encryption algorithms as described in https://tools.ietf.org/html/rfc7518#section-5
    14  type ContentEncryptionAlgorithm string
    15  
    16  // Supported values for ContentEncryptionAlgorithm
    17  const (
    18  	A128CBC_HS256 ContentEncryptionAlgorithm = "A128CBC-HS256" // AES-CBC + HMAC-SHA256 (128)
    19  	A128GCM       ContentEncryptionAlgorithm = "A128GCM"       // AES-GCM (128)
    20  	A192CBC_HS384 ContentEncryptionAlgorithm = "A192CBC-HS384" // AES-CBC + HMAC-SHA384 (192)
    21  	A192GCM       ContentEncryptionAlgorithm = "A192GCM"       // AES-GCM (192)
    22  	A256CBC_HS512 ContentEncryptionAlgorithm = "A256CBC-HS512" // AES-CBC + HMAC-SHA512 (256)
    23  	A256GCM       ContentEncryptionAlgorithm = "A256GCM"       // AES-GCM (256)
    24  )
    25  
    26  var allContentEncryptionAlgorithms = map[ContentEncryptionAlgorithm]struct{}{
    27  	A128CBC_HS256: {},
    28  	A128GCM:       {},
    29  	A192CBC_HS384: {},
    30  	A192GCM:       {},
    31  	A256CBC_HS512: {},
    32  	A256GCM:       {},
    33  }
    34  
    35  var listContentEncryptionAlgorithmOnce sync.Once
    36  var listContentEncryptionAlgorithm []ContentEncryptionAlgorithm
    37  
    38  // ContentEncryptionAlgorithms returns a list of all available values for ContentEncryptionAlgorithm
    39  func ContentEncryptionAlgorithms() []ContentEncryptionAlgorithm {
    40  	listContentEncryptionAlgorithmOnce.Do(func() {
    41  		listContentEncryptionAlgorithm = make([]ContentEncryptionAlgorithm, 0, len(allContentEncryptionAlgorithms))
    42  		for v := range allContentEncryptionAlgorithms {
    43  			listContentEncryptionAlgorithm = append(listContentEncryptionAlgorithm, v)
    44  		}
    45  		sort.Slice(listContentEncryptionAlgorithm, func(i, j int) bool {
    46  			return string(listContentEncryptionAlgorithm[i]) < string(listContentEncryptionAlgorithm[j])
    47  		})
    48  	})
    49  	return listContentEncryptionAlgorithm
    50  }
    51  
    52  // Accept is used when conversion from values given by
    53  // outside sources (such as JSON payloads) is required
    54  func (v *ContentEncryptionAlgorithm) Accept(value interface{}) error {
    55  	var tmp ContentEncryptionAlgorithm
    56  	if x, ok := value.(ContentEncryptionAlgorithm); ok {
    57  		tmp = x
    58  	} else {
    59  		var s string
    60  		switch x := value.(type) {
    61  		case fmt.Stringer:
    62  			s = x.String()
    63  		case string:
    64  			s = x
    65  		default:
    66  			return errors.Errorf(`invalid type for jwa.ContentEncryptionAlgorithm: %T`, value)
    67  		}
    68  		tmp = ContentEncryptionAlgorithm(s)
    69  	}
    70  	if _, ok := allContentEncryptionAlgorithms[tmp]; !ok {
    71  		return errors.Errorf(`invalid jwa.ContentEncryptionAlgorithm value`)
    72  	}
    73  
    74  	*v = tmp
    75  	return nil
    76  }
    77  
    78  // String returns the string representation of a ContentEncryptionAlgorithm
    79  func (v ContentEncryptionAlgorithm) String() string {
    80  	return string(v)
    81  }
    82  

View as plain text