pure.bend checks
raw source on the hub · import bend-kit-jwt@0.14.0.2/pure.bend as Pure
3 imports
import Base import bend-kit-json@0.7.3.0/json.bend as Json import bend-kit-bytes@0.3.3.1/bytes.bend as Bytes
Types
type Alg source · line 9 · raw
Data
HS256Alg
HS384Alg
HS512Alg
RS256Alg
ES256Alg
type Err source · line 16 · raw
Data
MalformedErr
AlgMismatchErr
CritErr
KeyTypeErr
WeakKeyErr
BadSigErr
BadClaimErr
ExpiredErr
NotYetErr
FutureErr
BadIssErr
BadAudErr
NoKeyErr
Crypto@code:U32 -> @why:String -> Err
type Policy source · line 32 · raw
Data
What verify accepts: the one alg, the issuer and audience when Some, and leeway seconds of clock skew.
Policy@alg:Alg -> @iss:Maybe<&2, String> -> @aud:Maybe<&2, String> -> @leeway:U32 -> Policy
type Lit source · line 144 · raw
Data
A NumericDate (RFC 7519 §2) rounded up to whole seconds and capped at the U32 top, or None when it is negative or has an exponent. Up is exact against a whole now: now >= t iff now >= ceil(t).
LStr@s:String -> Lit
LNum@t:Maybe<&2, U32> -> Lit
LStrs@xs:Maybe<&2, List<&2, String>> -> Lit
LOtherLit
type Field source · line 151 · raw
Data
One member: its name as octets, and what the checks need of its value.
Field@name:String -> @val:Lit -> Field
type Parts source · line 239 · raw
Type
A compact JWS: the header and claim members, the claims, the signing input, and the signature.
Parts@head:List<&2, Field> -> @facts:List<&2, Field> -> @claims:0x419ec39802735c4664960ab4b9d962e5/json.Val -> @input:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @sig:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Parts
type Jwk source · line 438 · raw
Data
A usable public key from a set: its kid, RSA or EC P-256, its alg ("" when the set gives none), and its two base64url parts (n and e, or x and y).
Jwk@kid:String -> @rsa:Bool -> @alg:String -> @a:String -> @b:String -> Jwk
Definitions
def policy source · line 35 · raw
@a:Alg -> Policy
def iss source · line 38 · raw
@p:Policy -> @s:String -> Policy
def aud source · line 42 · raw
@p:Policy -> @s:String -> Policy
def leeway source · line 46 · raw
@p:Policy -> @+n:U32 -> Policy
def policy.alg source · line 50 · raw
@p:Policy -> Alg
def alg.name source · line 54 · raw
@a:Alg -> String
def b64u.push source · line 69 · raw
@+c:U32 -> @acc:String -> String
def b64u.go source · line 80 · raw
@s:String -> @acc:String -> String
def b64u source · line 87 · raw
@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> String
def unb64u.c source · line 91 · raw
@+c:U32 -> U32
The standard alphabet's char for c. '+', '/', '=' and NUL become NUL, which no decoder accepts.
def unb64u.pad source · line 107 · raw
@+r:U32 -> @acc:String -> String
Padding for n mod 4 chars; 1 is never a whole group, so it gets a NUL.
def unb64u.go source · line 118 · raw
@s:String -> @acc:String -> @+n:U32 -> String
def unb64u.same source · line 125 · raw
@+s:String -> @r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> Maybe<&1, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes>
def unb64u.canon source · line 129 · raw
@+s:String -> @m:Maybe<&1, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes> -> Maybe<&1, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes>
def unb64u source · line 137 · raw
@+s:String -> Maybe<&1, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes>
Strict: only the URL-safe alphabet, no '=', and only the canonical text of its octets, so pad bits are 0.
def secs.digit source · line 154 · raw
@+acc:U32 -> @+d:U32 -> U32
def secs.up source · line 157 · raw
@+acc:U32 -> @frac:Bool -> U32
def secs.go source · line 161 · raw
@s:String -> @+acc:U32 -> @+frac:Bool -> @+point:Bool -> @+ok:Bool -> Maybe<&2, U32>
The JSON parser has checked the grammar, so only digits and one '.' need telling apart.
def secs source · line 172 · raw
@s:String -> Maybe<&2, U32>
def str.of source · line 175 · raw
@v:0x419ec39802735c4664960ab4b9d962e5/json.Val -> Maybe<&2, String>
def strs.push source · line 182 · raw
@s:Maybe<&2, String> -> @acc:Maybe<&2, List<&2, String>> -> Maybe<&2, List<&2, String>>
def strs source · line 189 · raw
@xs:List<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val> -> @acc:Maybe<&2, List<&2, String>> -> Maybe<&2, List<&2, String>>
def lit source · line 196 · raw
@v:0x419ec39802735c4664960ab4b9d962e5/json.Val -> Lit
def fields source · line 208 · raw
@kvs:List<&1, Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0x419ec39802735c4664960ab4b9d962e5/json.Val)> -> @acc:List<&2, Field> -> List<&2, Field>
An object's members, names as octets, last first.
def field source · line 215 · raw
@l:List<&2, Field> -> @+k:String -> Maybe<&2, Lit>
def has source · line 222 · raw
@l:List<&2, Field> -> @+k:String -> Bool
def str source · line 229 · raw
@m:Maybe<&2, Lit> -> Maybe<&2, String>
def parse.json source · line 244 · raw
@h:Maybe<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val> -> @f:Maybe<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val> -> @c:Maybe<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val> -> @input:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @sig:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Result<&1, &1, Err, Parts>
RFC 7515 §5.2 allows rejecting repeated names; a second "alg" is how parsers come to disagree. parse.claims rejects them at every depth with Json.unique.parsed before members get here.
def parse.claims source · line 252 · raw
@hb:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> @input:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @sig:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Result<&1, &1, Err, Parts>
def parse.segs source · line 256 · raw
@h:Maybe<&1, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes> -> @c:Maybe<&1, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes> -> @s:Maybe<&1, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes> -> @input:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Result<&1, &1, Err, Parts>
def parse.split source · line 264 · raw
@xs:List<&2, String> -> Result<&1, &1, Err, Parts>
def parse source · line 272 · raw
@token:String -> Result<&1, &1, Err, Parts>
Three strict base64url segments, the first two JSON objects with no repeated names.
def fail.if source · line 277 · raw
@bad:Bool -> @+e:Err -> Result<&1, &1, Err, Unit>
def head.alg source · line 284 · raw
@m:Maybe<&2, Lit> -> Result<&1, &1, Err, String>
def head.check source · line 293 · raw
@+a:Alg -> @+h:List<&2, Field> -> Result<&1, &1, Err, Unit>
The header's alg is exactly the pinned one, and it asks for no extension: crit (RFC 7515 §4.1.11) and b64 (RFC 7797) change how the token must be read, and neither is implemented.
def when source · line 299 · raw
@m:Maybe<&2, Lit> -> Result<&1, &1, Err, Maybe<&2, U32>>
def text source · line 308 · raw
@m:Maybe<&2, Lit> -> Result<&1, &1, Err, Maybe<&2, String>>
def auds source · line 318 · raw
@m:Maybe<&2, Lit> -> Result<&1, &1, Err, Maybe<&2, List<&2, String>>>
RFC 7519 §4.1.3: aud is one string or an array of them.
def late source · line 330 · raw
@+now:U32 -> @+lw:U32 -> @m:Maybe<&2, U32> -> Bool
exp (RFC 7519 §4.1.4): now must be before it; late by at least leeway fails.
def early source · line 338 · raw
@+now:U32 -> @+lw:U32 -> @m:Maybe<&2, U32> -> Bool
nbf and iat: at most leeway seconds in the future.
def octets source · line 345 · raw
@s:String -> String
def iss.bad source · line 348 · raw
@want:Maybe<&2, String> -> @got:Maybe<&2, String> -> Bool
def aud.has source · line 357 · raw
@l:List<&2, String> -> @+a:String -> Bool
def aud.bad source · line 365 · raw
@want:Maybe<&2, String> -> @got:Maybe<&2, List<&2, String>> -> Bool
RFC 7519 §4.1.3: a token with an aud that does not name us fails, as does one without aud when we want one.
def claims.check source · line 377 · raw
@p:Policy -> @+now:U32 -> @+c:List<&2, Field> -> Result<&1, &1, Err, Unit>
The registered claims of c at unix time now.
def inspect.parts source · line 391 · raw
@+p:Policy -> @+now:U32 -> @r:Result<&1, &1, Err, Parts> -> Result<&1, &1, Err, Unit>
def inspect source · line 401 · raw
@p:Policy -> @token:String -> @+now:U32 -> Result<&1, &1, Err, Unit>
The header and claims of token, without its signature: the pure half of verify.
def header.kid source · line 404 · raw
@m:Maybe<&2, String> -> List<&1, Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0x419ec39802735c4664960ab4b9d962e5/json.Val)>
def header source · line 412 · raw
@a:Alg -> @kid:Maybe<&2, String> -> 0x419ec39802735c4664960ab4b9d962e5/json.Val
{"alg":..,"typ":"JWT"}, then "kid" when given.
def signing.input source · line 416 · raw
@a:Alg -> @kid:Maybe<&2, String> -> @body:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> String
header.body in base64url, body being the compact JSON claims: the text the signature covers.
def sign.done source · line 419 · raw
@+input:String -> @s:Result<&1, &1, Err, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes> -> Result<&1, &1, Err, String>
def sign.obj source · line 427 · raw
@m:Maybe<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val> -> Bool
verify accepts only an object with no repeated names, so sign makes no other kind.
def jwk.two source · line 441 · raw
@+rsa:Bool -> @+kid:String -> @+alg:String -> @a:Maybe<&2, String> -> @b:Maybe<&2, String> -> Maybe<&2, Jwk>
def jwk.alg source · line 449 · raw
@m:Maybe<&2, Lit> -> String
An alg member that is not a string can match no pinned alg.
def jwk.use source · line 458 · raw
@m:Maybe<&2, Lit> -> Maybe<&2, Unit>
def jwk.kty source · line 467 · raw
@+kty:String -> @+kid:String -> @+f:List<&2, Field> -> Maybe<&2, Jwk>
def jwk.fields source · line 473 · raw
@+f:List<&2, Field> -> Maybe<&2, Jwk>
def jwk.obj source · line 480 · raw
@m:Maybe<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val> -> Maybe<&2, Jwk>
def jwk.of source · line 488 · raw
@v:0x419ec39802735c4664960ab4b9d962e5/json.Val -> Maybe<&2, Jwk>
A key whose members repeat a name, at any depth, is skipped.
def jwk.push source · line 491 · raw
@m:Maybe<&2, Jwk> -> @acc:List<&2, Jwk> -> List<&2, Jwk>
def jwks.go source · line 498 · raw
@xs:List<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val> -> @acc:List<&2, Jwk> -> List<&2, Jwk>
def jwks.arr source · line 505 · raw
@m:Maybe<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val> -> Maybe<&2, List<&2, Jwk>>
def jwks.doc source · line 512 · raw
@m:Maybe<&1, 0x419ec39802735c4664960ab4b9d962e5/json.Val> -> Maybe<&2, List<&2, Jwk>>
def jwks.parse source · line 521 · raw
@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> Maybe<&2, List<&2, Jwk>>
The signing keys of a JWK Set document; members it cannot use (enc keys, other curves, oct) are skipped. None when the document is not {"keys": [...]}.
def fam source · line 524 · raw
@a:Alg -> U32
def jwk.fits source · line 533 · raw
@k:Jwk -> @+kid:String -> @+a:Alg -> Bool
def jwk.pick source · line 539 · raw
@ks:List<&2, Jwk> -> @+kid:String -> @+a:Alg -> Maybe<&2, Jwk>
The first key named kid that can check alg a. RFC 7515 §4.1.4 leaves kid matching to exact comparison.