API Reference
stJose
JOSE (JWK / JWS) Unit
Classes, interfaces and records
classeJoseError
inherits from Exception
eJoseError is raised for every failure in this unit: a component that exposes no private signing key, an unsupported key type or curve, missing RSA modulus or exponent, a public point that is not a well-formed encoding, or an algorithm request that conflicts with the key. An application wraps tJoseKey construction and signing to catch it.
(no public members)
classtJoseKey
constructor Create(aKeyComponent: TComponent; aAlgorithm: tJoseAlgorithm = jalgNone);
Create infers the family and, unless aAlgorithm names one explicitly, the JOSE algorithm. Only RSA algorithms are genuinely selectable: an EC key's algorithm follows its curve, and EdDSA has only one.
function AlgorithmName: string;
AlgorithmName is the registered JOSE "alg" string for the resolved algorithm (e.g. "RS256", "ES256", "EdDSA"); it is what JwsFlattened writes into the protected header's "alg" member.
function PublicJwk: tJsonValue;
PublicJwk returns a freshly built JWK containing only the public members required for this key type; the caller owns the result.
function Thumbprint: string;
Thumbprint is BASE64URL(SHA-256(canonical JWK)) per RFC 7638 - the value an ACME key authorization is built from.
function Sign(const aSigningInput: tBytes): tBytes;
Sign returns the raw JOSE signature octets over aSigningInput: PKCS#1 v1.5 or PSS for RSA, fixed-width r||s for ECDSA, R||S for EdDSA.
property Family: tJoseKeyFamily read fFamily;
Family reports which of the three key families the supplied component resolved to; Create raises rather than ever leaving it jkfNone. Read it to branch on key type without re-inspecting the underlying key component.
property Algorithm: tJoseAlgorithm read fAlgorithm;
Algorithm is the resolved JOSE algorithm as an enum, of which AlgorithmName is the string form: the chosen or defaulted RS* or PS* for RSA, the curve-fixed ES* for ECDSA, jalgEdDSA for an Edwards key.
property CurveName: string read fCurveName;
CurveName is the JWK "crv" value the JWK builders emit - "P-256", "P-384" or "P-521" for ECDSA and "Ed25519" or "Ed448" for EdDSA; it is empty for an RSA key, which has no curve.
Types (enumerations, sets, aliases)
enumtJoseAlgorithm
tJoseAlgorithm enumerates the JOSE "alg" values this unit can produce:
jalgNone (unresolved), the RSA PKCS#1 v1.5 RS* and PSS PS* set, the ECDSA ES* set and jalgEdDSA. JoseAlgorithmName maps each to its registered string.
tJoseAlgorithm = (jalgNone,
jalgRS256, jalgRS384, jalgRS512,
jalgPS256, jalgPS384, jalgPS512,
jalgES256, jalgES384, jalgES512,
jalgEdDSA);
enumtJoseKeyFamily
tJoseKeyFamily is the coarse key class Resolve assigns from the supplied component: jkfNone only transiently, then jkfRSA, jkfECDSA or jkfEdDSA. It is surfaced by the tJoseKey.Family property.
tJoseKeyFamily = (jkfNone, jkfRSA, jkfECDSA, jkfEdDSA);
Routines