Debian Codegraph @

jose/types.go

raw symbols SCIP
1 // Code generated (comment to force golint to ignore this file). DO NOT EDIT.
2
3 package jose
4
5 import (
6 "errors"
7 "strings"
8 "time"
9
10 jose "gopkg.in/square/go-jose.v2"
11 "gopkg.in/square/go-jose.v2/jwt"
12 )
13
14 // SupportsPBKDF2 constant to know if the underlaying library supports
15 // password based cryptography algorithms.
16 const SupportsPBKDF2 = true
17
18 // PBKDF2SaltSize is the default size of the salt for PBKDF2, 128-bit salt.
19 const PBKDF2SaltSize = 16
20
21 // PBKDF2Iterations is the default number of iterations for PBKDF2, 100k
22 // iterations. Nist recommends at least 10k, 1Passsword uses 100k.
23 const PBKDF2Iterations = 100000
24
25 // JSONWebSignature represents a signed JWS object after parsing.
26 type JSONWebSignature = jose.JSONWebSignature
27
28 // JSONWebToken represents a JSON Web Token (as specified in RFC7519).
29 type JSONWebToken = jwt.JSONWebToken
30
31 // JSONWebKey represents a public or private key in JWK format.
32 type JSONWebKey = jose.JSONWebKey
33
34 // JSONWebKeySet represents a JWK Set object.
35 type JSONWebKeySet = jose.JSONWebKeySet
36
37 // JSONWebEncryption represents an encrypted JWE object after parsing.
38 type JSONWebEncryption = jose.JSONWebEncryption
39
40 // Recipient represents an algorithm/key to encrypt messages to.
41 type Recipient = jose.Recipient
42
43 // EncrypterOptions represents options that can be set on new encrypters.
44 type EncrypterOptions = jose.EncrypterOptions
45
46 // Encrypter represents an encrypter which produces an encrypted JWE object.
47 type Encrypter = jose.Encrypter
48
49 // ContentType represents type of the contained data.
50 type ContentType = jose.ContentType
51
52 // KeyAlgorithm represents a key management algorithm.
53 type KeyAlgorithm = jose.KeyAlgorithm
54
55 // ContentEncryption represents a content encryption algorithm.
56 type ContentEncryption = jose.ContentEncryption
57
58 // SignatureAlgorithm represents a signature (or MAC) algorithm.
59 type SignatureAlgorithm = jose.SignatureAlgorithm
60
61 // Signature represents a signature.
62 type Signature = jose.Signature
63
64 // ErrCryptoFailure indicates an error in a cryptographic primitive.
65 var ErrCryptoFailure = jose.ErrCryptoFailure
66
67 // Claims represents public claim values (as specified in RFC 7519).
68 type Claims = jwt.Claims
69
70 // Builder is a utility for making JSON Web Tokens. Calls can be chained, and
71 // errors are accumulated until the final call to CompactSerialize/FullSerialize.
72 type Builder = jwt.Builder
73
74 // NumericDate represents date and time as the number of seconds since the
75 // epoch, including leap seconds. Non-integer values can be represented
76 // in the serialized format, but we round to the nearest second.
77 type NumericDate = jwt.NumericDate
78
79 // Audience represents the recipients that the token is intended for.
80 type Audience = jwt.Audience
81
82 // Expected defines values used for protected claims validation.
83 // If field has zero value then validation is skipped.
84 type Expected = jwt.Expected
85
86 // Signer represents a signer which takes a payload and produces a signed JWS object.
87 type Signer = jose.Signer
88
89 // SigningKey represents an algorithm/key used to sign a message.
90 type SigningKey = jose.SigningKey
91
92 // SignerOptions represents options that can be set when creating signers.
93 type SignerOptions = jose.SignerOptions
94
95 // Header represents the read-only JOSE header for JWE/JWS objects.
96 type Header = jose.Header
97
98 // HeaderKey represents the type used as a key in the protected header of a JWS
99 // object.
100 type HeaderKey = jose.HeaderKey
101
102 // ErrInvalidIssuer indicates invalid iss claim.
103 var ErrInvalidIssuer = jwt.ErrInvalidIssuer
104
105 // ErrInvalidAudience indicated invalid aud claim.
106 var ErrInvalidAudience = jwt.ErrInvalidAudience
107
108 // ErrNotValidYet indicates that token is used before time indicated in nbf claim.
109 var ErrNotValidYet = jwt.ErrNotValidYet
110
111 // ErrExpired indicates that token is used after expiry time indicated in exp claim.
112 var ErrExpired = jwt.ErrExpired
113
114 // ErrInvalidSubject indicates invalid sub claim.
115 var ErrInvalidSubject = jwt.ErrInvalidSubject
116
117 // ErrInvalidID indicates invalid jti claim.
118 var ErrInvalidID = jwt.ErrInvalidID
119
120 // Key management algorithms
121 const (
122 RSA1_5 = KeyAlgorithm("RSA1_5") // RSA-PKCS1v1.5
123 RSA_OAEP = KeyAlgorithm("RSA-OAEP") // RSA-OAEP-SHA1
124 RSA_OAEP_256 = KeyAlgorithm("RSA-OAEP-256") // RSA-OAEP-SHA256
125 A128KW = KeyAlgorithm("A128KW") // AES key wrap (128)
126 A192KW = KeyAlgorithm("A192KW") // AES key wrap (192)
127 A256KW = KeyAlgorithm("A256KW") // AES key wrap (256)
128 DIRECT = KeyAlgorithm("dir") // Direct encryption
129 ECDH_ES = KeyAlgorithm("ECDH-ES") // ECDH-ES
130 ECDH_ES_A128KW = KeyAlgorithm("ECDH-ES+A128KW") // ECDH-ES + AES key wrap (128)
131 ECDH_ES_A192KW = KeyAlgorithm("ECDH-ES+A192KW") // ECDH-ES + AES key wrap (192)
132 ECDH_ES_A256KW = KeyAlgorithm("ECDH-ES+A256KW") // ECDH-ES + AES key wrap (256)
133 A128GCMKW = KeyAlgorithm("A128GCMKW") // AES-GCM key wrap (128)
134 A192GCMKW = KeyAlgorithm("A192GCMKW") // AES-GCM key wrap (192)
135 A256GCMKW = KeyAlgorithm("A256GCMKW") // AES-GCM key wrap (256)
136 PBES2_HS256_A128KW = KeyAlgorithm("PBES2-HS256+A128KW") // PBES2 + HMAC-SHA256 + AES key wrap (128)
137 PBES2_HS384_A192KW = KeyAlgorithm("PBES2-HS384+A192KW") // PBES2 + HMAC-SHA384 + AES key wrap (192)
138 PBES2_HS512_A256KW = KeyAlgorithm("PBES2-HS512+A256KW") // PBES2 + HMAC-SHA512 + AES key wrap (256)
139 )
140
141 // Signature algorithms
142 const (
143 HS256 = "HS256" // HMAC using SHA-256
144 HS384 = "HS384" // HMAC using SHA-384
145 HS512 = "HS512" // HMAC using SHA-512
146 RS256 = "RS256" // RSASSA-PKCS-v1.5 using SHA-256
147 RS384 = "RS384" // RSASSA-PKCS-v1.5 using SHA-384
148 RS512 = "RS512" // RSASSA-PKCS-v1.5 using SHA-512
149 ES256 = "ES256" // ECDSA using P-256 and SHA-256
150 ES384 = "ES384" // ECDSA using P-384 and SHA-384
151 ES512 = "ES512" // ECDSA using P-521 and SHA-512
152 PS256 = "PS256" // RSASSA-PSS using SHA256 and MGF1-SHA256
153 PS384 = "PS384" // RSASSA-PSS using SHA384 and MGF1-SHA384
154 PS512 = "PS512" // RSASSA-PSS using SHA512 and MGF1-SHA512
155 EdDSA = "EdDSA" // Ed25591
156 )
157
158 // Content encryption algorithms
159 const (
160 A128CBC_HS256 = ContentEncryption("A128CBC-HS256") // AES-CBC + HMAC-SHA256 (128)
161 A192CBC_HS384 = ContentEncryption("A192CBC-HS384") // AES-CBC + HMAC-SHA384 (192)
162 A256CBC_HS512 = ContentEncryption("A256CBC-HS512") // AES-CBC + HMAC-SHA512 (256)
163 A128GCM = ContentEncryption("A128GCM") // AES-GCM (128)
164 A192GCM = ContentEncryption("A192GCM") // AES-GCM (192)
165 A256GCM = ContentEncryption("A256GCM") // AES-GCM (256)
166 )
167
168 // Elliptic curves
169 const (
170 P256 = "P-256" // P-256 curve (FIPS 186-3)
171 P384 = "P-384" // P-384 curve (FIPS 186-3)
172 P521 = "P-521" // P-521 curve (FIPS 186-3)
173 )
174
175 // Key types
176 const (
177 EC = "EC" // Elliptic curves
178 RSA = "RSA" // RSA
179 OKP = "OKP" // Ed25519
180 OCT = "oct" // Octet sequence
181 )
182
183 // Ed25519 is the EdDSA signature scheme using SHA-512/256 and Curve25519
184 const Ed25519 = "Ed25519"
185
186 // Default key management, signature, and content encryption algorithms to use if none is specified.
187 const (
188 // Key management algorithms
189 DefaultECKeyAlgorithm = ECDH_ES
190 DefaultRSAKeyAlgorithm = RSA_OAEP_256
191 DefaultOctKeyAlgorithm = A256GCMKW
192 // Signature algorithms
193 DefaultRSASigAlgorithm = RS256
194 DefaultOctSigsAlgorithm = HS256
195 // Content encryption algorithm
196 DefaultEncAlgorithm = A256GCM
197 )
198
199 // Default sizes
200 const (
201 DefaultRSASize = 2048
202 DefaultOctSize = 32
203 )
204
205 // ParseEncrypted parses an encrypted message in compact or full serialization format.
206 func ParseEncrypted(input string) (*JSONWebEncryption, error) {
207 return jose.ParseEncrypted(input)
208 }
209
210 // NewEncrypter creates an appropriate encrypter based on the key type.
211 func NewEncrypter(enc ContentEncryption, rcpt Recipient, opts *EncrypterOptions) (Encrypter, error) {
212 return jose.NewEncrypter(enc, rcpt, opts)
213 }
214
215 // NewNumericDate constructs NumericDate from time.Time value.
216 func NewNumericDate(t time.Time) *NumericDate {
217 return jwt.NewNumericDate(t)
218 }
219
220 // UnixNumericDate returns a NumericDate from the given seconds since the UNIX
221 // Epoch time. For backward compatibility is s is 0, a nil value will be returned.
222 func UnixNumericDate(s int64) *NumericDate {
223 if s == 0 {
224 return nil
225 }
226 out := NumericDate(s)
227 return &out
228 }
229
230 // NewSigner creates an appropriate signer based on the key type
231 func NewSigner(sig SigningKey, opts *SignerOptions) (Signer, error) {
232 return jose.NewSigner(sig, opts)
233 }
234
235 // ParseSigned parses token from JWS form.
236 func ParseSigned(s string) (*JSONWebToken, error) {
237 return jwt.ParseSigned(s)
238 }
239
240 // Signed creates builder for signed tokens.
241 func Signed(sig Signer) Builder {
242 return jwt.Signed(sig)
243 }
244
245 // ParseJWS parses a signed message in compact or full serialization format.
246 func ParseJWS(s string) (*JSONWebSignature, error) {
247 return jose.ParseSigned(s)
248 }
249
250 // Determine whether a JSONWebKey is symmetric
251 func IsSymmetric(k *JSONWebKey) bool {
252 switch k.Key.(type) {
253 case []byte:
254 return true
255 default:
256 return false
257 }
258 }
259
260 // Determine whether a JSONWebKey is asymmetric
261 func IsAsymmetric(k *JSONWebKey) bool {
262 return !IsSymmetric(k)
263 }
264
265 // TrimPrefix removes the string "square/go-jose" from all errors.
266 func TrimPrefix(err error) error {
267 if err == nil {
268 return nil
269 }
270 return errors.New(strings.TrimPrefix(err.Error(), "square/go-jose: "))
271 }