4
4
import { RequestLike } from "../types" ;
5
5
import { lcObjectKey } from "../utils" ;
6
6
7
+ /**
8
+ * Class for creating signature base,
9
+ * construct with a request or a response
10
+ */
7
11
export class RFC9421SignatureBaseFactory {
8
12
public static availableDerivedComponents : [
9
13
'@signature-params' ,
@@ -34,16 +38,14 @@ export class RFC9421SignatureBaseFactory {
34
38
35
39
/**
36
40
* 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'
41
42
* @returns component value
42
43
*/
43
44
public get (
44
- type : typeof RFC9421SignatureBaseFactory . availableDerivedComponents [ number ] | string ,
45
- params : string [ ] = [ ] ,
45
+ component : string ,
46
46
) : string {
47
+ const params = component . split ( ';' ) ;
48
+ let type = params [ 0 ] ;
47
49
if ( ! type ) {
48
50
throw new Error ( 'Type is empty' ) ;
49
51
}
@@ -53,6 +55,7 @@ export class RFC9421SignatureBaseFactory {
53
55
}
54
56
throw new Error ( `Invalid component type string: ${ type } ` ) ;
55
57
}
58
+
56
59
if ( type === '@signature-params' ) {
57
60
if ( ! this . signatureParams ) {
58
61
throw new Error ( 'signatureParams is not provided' ) ;
@@ -156,7 +159,7 @@ export function genRFC9421SignatureBase(
156
159
throw new Error ( 'You request req component but req is not provided' ) ;
157
160
}
158
161
159
- push ( params [ 0 ] , currentFactory . get ( params [ 0 ] , params ) ) ;
162
+ push ( params [ 0 ] , currentFactory . get ( component ) ) ;
160
163
}
161
164
162
165
return Array . from ( results . entries ( ) , ( [ key , value ] ) => `${ key } : ${ value } ` ) . join ( '\n' ) ;
0 commit comments