Skip to content

Commit 2408f36

Browse files
committed
RFC 9530 終わり
1 parent 14bb186 commit 2408f36

12 files changed

+724
-70
lines changed

dist/digest/digest-rfc3230.d.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,21 @@ import { DigestSource } from './utils.js';
22
import { DigestHashAlgorithm, IncomingRequest } from '../types.js';
33
export declare function genRFC3230DigestHeader(body: DigestSource, hashAlgorithm: DigestHashAlgorithm): Promise<string>;
44
export declare const digestHeaderRegEx: RegExp;
5-
export declare function verifyRFC3230DigestHeader(request: IncomingRequest, rawBody: DigestSource, failOnNoDigest?: boolean, errorLogger?: ((message: any) => any)): Promise<boolean>;
5+
/**
6+
* @param request Incoming request
7+
* @param rawBody Raw body
8+
* @param failOnNoDigest If false, return true when no Digest header is found (default: true)
9+
* @param errorLogger When returing false, called with the error message
10+
* @returns Promise<boolean>
11+
*/
12+
export declare function verifyRFC3230DigestHeader(request: IncomingRequest, rawBody: DigestSource, opts?: boolean | {
13+
/**
14+
* If false, return true when no Digest header is found
15+
* @default true
16+
*/
17+
failOnNoDigest?: boolean;
18+
/**
19+
* Specify hash algorithms you accept (Web Crypto API algorithm names)
20+
*/
21+
algorithms: DigestHashAlgorithm[];
22+
}, errorLogger?: ((message: any) => any)): Promise<boolean>;

dist/digest/digest-rfc9530.d.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { DigestSource } from './utils.js';
2+
import type { DigestHashAlgorithm, IncomingRequest } from '../types.js';
3+
import * as sh from 'structured-headers';
4+
export declare class RFC9530GenerateDigestHeaderError extends Error {
5+
constructor(message: string);
6+
}
7+
export type RFC9530HashAlgorithmStatus = 'Active' | 'Provisional' | 'Deprecated';
8+
export declare const RFC9530HashAlgorithmRegistry: {
9+
'sha-512': "Active";
10+
'sha-256': "Active";
11+
md5: "Deprecated";
12+
sha: "Deprecated";
13+
unixsum: "Deprecated";
14+
unixcksum: "Deprecated";
15+
adler: "Deprecated";
16+
crc32c: "Deprecated";
17+
};
18+
export type RFC9530HashAlgorithm = keyof typeof RFC9530HashAlgorithmRegistry;
19+
export declare const supportedHashAlgorithmsWithRFC9530AndWebCrypto: ("sha-512" | "sha-256")[];
20+
/**
21+
* Want-*-Digest parsed by structured-headers.parseDictionary
22+
* https://datatracker.ietf.org/doc/html/rfc9530#name-integrity-preference-fields
23+
*/
24+
export type RFC9530Prefernece = Map<string, [number, Map<any, any>]>;
25+
export declare function convertHashAlgorithmFromWebCryptoToRFC9530(algo: DigestHashAlgorithm): RFC9530HashAlgorithm;
26+
/**
27+
* @param prefernece Prefernece map (Want-*-Digest field parsed by structured-headers.parseDictionary)
28+
* @param meAcceptable The hash algorithms that You can accept or use
29+
* @returns
30+
*/
31+
export declare function chooseRFC9530HashAlgorithmByPreference(prefernece: RFC9530Prefernece, meAcceptable?: RFC9530HashAlgorithm[]): RFC9530HashAlgorithm | null;
32+
export type RFC9530DigestHeaderObject = [string, [sh.ByteSequence, Map<any, any>]][];
33+
/**
34+
* Generate single Digest header
35+
* @param body The body to be hashed
36+
* @param hashAlgorithm
37+
* Supported common to RFC 9530 Registered and SubtleCrypto.digest = Only 'SHA-256' and 'SHA-512'
38+
* @returns `[[algorithm, [ByteSequence, Map(0)]]]`
39+
* To convert to string, use serializeDictionary from structured-headers
40+
*/
41+
export declare function genSingleRFC9530DigestHeader(body: DigestSource, hashAlgorithm: string): Promise<RFC9530DigestHeaderObject>;
42+
/**
43+
* Generate Digest header
44+
* @param body The body to be hashed
45+
* @param hashAlgorithms
46+
* Supported common to RFC 9530 Registered and SubtleCrypto.digest = Only 'SHA-256' and 'SHA-512'
47+
* @param process
48+
* 'concurrent' to use Promise.all, 'sequential' to use for..of
49+
* @default 'concurrent'
50+
* @returns `[algorithm, [ByteSequence, Map(0)]][]`
51+
* To convert to string, use serializeDictionary from structured-headers
52+
*/
53+
export declare function genRFC9530DigestHeader(body: DigestSource, hashAlgorithms?: string | RFC9530Prefernece | Iterable<string>, process?: 'concurrent' | 'sequential'): Promise<RFC9530DigestHeaderObject>;
54+
/**
55+
* Verify Content-Digest header (not Repr-Digest)
56+
* @param request IncomingRequest
57+
* @param rawBody Raw body
58+
* @param opts Options
59+
* @param errorLogger Error logger when verification fails
60+
* @returns Whether digest is valid with the body
61+
*/
62+
export declare function verifyRFC9530DigestHeader(request: IncomingRequest, rawBody: DigestSource, opts?: {
63+
/**
64+
* If false, return true when no Digest header is found
65+
* @default true
66+
*/
67+
failOnNoDigest?: boolean;
68+
/**
69+
* If true, verify all digests without not supported algorithms
70+
* If false, use the first supported and exisiting algorithm in hashAlgorithms
71+
* @default true
72+
*/
73+
verifyAll?: boolean;
74+
/**
75+
* Specify hash algorithms you accept. (RFC 9530 algorithm registries)
76+
*
77+
* If `varifyAll: false`, it is also used to choose the hash algorithm to verify.
78+
* (Younger index is preferred.)
79+
*/
80+
hashAlgorithms?: RFC9530HashAlgorithm[];
81+
}, errorLogger?: ((message: any) => any)): Promise<boolean>;

dist/digest/digest.d.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1-
import { IncomingRequest } from "../types.js";
1+
import { DigestHashAlgorithm, IncomingRequest } from "../types.js";
22
import { DigestSource } from "./utils.js";
3-
export declare function verifyDigestHeader(request: IncomingRequest, rawBody: DigestSource, failOnNoDigest?: boolean, errorLogger?: ((message: any) => any)): Promise<boolean>;
3+
export declare function verifyDigestHeader(request: IncomingRequest, rawBody: DigestSource, opts?: boolean | {
4+
/**
5+
* If false, return true when no Digest header is found
6+
* @default true
7+
*/
8+
failOnNoDigest?: boolean;
9+
/**
10+
* Specify hash algorithms you accept (Web Crypto API algorithm names)
11+
*/
12+
algorithms: DigestHashAlgorithm[];
13+
/**
14+
* RFC 9530 (Content-Digest) only
15+
* If true, verify all digests without not supported algorithms
16+
* If false, use the first supported and exisiting algorithm in hashAlgorithms
17+
* @default true
18+
*/
19+
verifyAll?: boolean;
20+
}, errorLogger?: ((message: any) => any)): Promise<boolean>;

0 commit comments

Comments
 (0)