Skip to content

Commit c9f9850

Browse files
committed
parse component by the factory
1 parent 52a08ad commit c9f9850

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/rfc9421/sign.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
import { RequestLike } from "../types";
55
import { lcObjectKey } from "../utils";
66

7+
/**
8+
* Class for creating signature base,
9+
* construct with a request or a response
10+
*/
711
export class RFC9421SignatureBaseFactory {
812
public static availableDerivedComponents: [
913
'@signature-params',
@@ -34,16 +38,14 @@ export class RFC9421SignatureBaseFactory {
3438

3539
/**
3640
* Return component value from component type and parameters
37-
* @param type component type (first part of component key)
38-
* e.g. `@method` or `"@method"`
39-
* @param params component parameters
40-
* e.g. ['"@query-param"', 'name="foo"'] (Result of '"@query-param";name="foo"'.split(';'))
41+
* @param component e.g. '"@query-param";name="foo"', '@method', 'content-digest'
4142
* @returns component value
4243
*/
4344
public get(
44-
type: typeof RFC9421SignatureBaseFactory.availableDerivedComponents[number] | string,
45-
params: string[] = [],
45+
component: string,
4646
): string {
47+
const params = component.split(';');
48+
let type = params[0];
4749
if (!type) {
4850
throw new Error('Type is empty');
4951
}
@@ -53,6 +55,7 @@ export class RFC9421SignatureBaseFactory {
5355
}
5456
throw new Error(`Invalid component type string: ${type}`);
5557
}
58+
5659
if (type === '@signature-params') {
5760
if (!this.signatureParams) {
5861
throw new Error('signatureParams is not provided');
@@ -156,7 +159,7 @@ export function genRFC9421SignatureBase(
156159
throw new Error('You request req component but req is not provided');
157160
}
158161

159-
push(params[0], currentFactory.get(params[0], params));
162+
push(params[0], currentFactory.get(component));
160163
}
161164

162165
return Array.from(results.entries(), ([key, value]) => `${key}: ${value}`).join('\n');

0 commit comments

Comments
 (0)