|
1 | | -import { hex } from "./deps.ts"; |
2 | 1 | import { toAmz, toDateStamp } from "./src/date.ts"; |
3 | 2 | export { toAmz, toDateStamp }; |
4 | 3 | import { getSignatureKey, signAwsV4 } from "./src/signing.ts"; |
| 4 | +import { sha256Hex } from "./src/util.ts"; |
5 | 5 |
|
6 | 6 | /** |
7 | 7 | * Generic AWS Signer interface |
@@ -96,15 +96,13 @@ export class AWSSignerV4 implements Signer { |
96 | 96 | const body = request.body |
97 | 97 | ? new Uint8Array(await request.arrayBuffer()) |
98 | 98 | : null; |
99 | | - const payloadHash = await sha256(body ?? new Uint8Array(0)); |
| 99 | + const payloadHash = await sha256Hex(body ?? new Uint8Array(0)); |
100 | 100 |
|
101 | 101 | const { awsAccessKeyId, awsSecretKey } = this.credentials; |
102 | 102 |
|
103 | 103 | const canonicalRequest = |
104 | 104 | `${request.method}\n${pathname}\n${canonicalQuerystring}\n${canonicalHeaders}\n${signedHeaders}\n${payloadHash}`; |
105 | | - const canonicalRequestDigest = await sha256( |
106 | | - new TextEncoder().encode(canonicalRequest), |
107 | | - ); |
| 105 | + const canonicalRequestDigest = await sha256Hex(canonicalRequest); |
108 | 106 |
|
109 | 107 | const algorithm = "AWS4-HMAC-SHA256"; |
110 | 108 | const credentialScope = |
@@ -159,9 +157,3 @@ export class AWSSignerV4 implements Signer { |
159 | 157 | return AWS_REGION; |
160 | 158 | }; |
161 | 159 | } |
162 | | - |
163 | | -async function sha256(data: Uint8Array): Promise<string> { |
164 | | - const hash = await crypto.subtle.digest("SHA-256", data); |
165 | | - const hexBytes = hex.encode(new Uint8Array(hash)); |
166 | | - return new TextDecoder().decode(hexBytes); |
167 | | -} |
0 commit comments