Skip to content

Commit 3bf4e00

Browse files
committed
format
1 parent 656c257 commit 3bf4e00

File tree

18 files changed

+164
-89
lines changed

18 files changed

+164
-89
lines changed

modules/cache-material/src/build_cryptographic_materials_cache_key_helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function buildCryptographicMaterialsCacheKeyHelpers<
2222
sha512: (...data: (Uint8Array | string)[]) => Promise<Uint8Array>
2323
): CryptographicMaterialsCacheKeyHelpersInterface<S> {
2424
const { serializeEncryptionContext, serializeEncryptedDataKey } =
25-
serializeFactory(fromUtf8, {utf8Sorting: false})
25+
serializeFactory(fromUtf8, { utf8Sorting: false })
2626

2727
return {
2828
buildEncryptionMaterialCacheKey,
@@ -80,7 +80,9 @@ export function buildCryptographicMaterialsCacheKeyHelpers<
8080
* However, the RAW Keyring wants _only_ the ADD.
8181
* So, I just slice off the length.
8282
*/
83-
const serializedContext = serializeEncryptionContext(context, {utf8Sorting: false}).slice(2)
83+
const serializedContext = serializeEncryptionContext(context, {
84+
utf8Sorting: false,
85+
}).slice(2)
8486
return sha512(serializedContext)
8587
}
8688
}

modules/decrypt-browser/src/decrypt_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function buildDecrypt(
2222
} {
2323
const {
2424
commitmentPolicy = CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT,
25-
maxEncryptedDataKeys = false
25+
maxEncryptedDataKeys = false,
2626
} = typeof options === 'string' ? { commitmentPolicy: options } : options
2727

2828
/* Precondition: browser buildDecrypt needs a valid commitmentPolicy. */
@@ -35,7 +35,7 @@ export function buildDecrypt(
3535

3636
const clientOptions: ClientOptions = {
3737
commitmentPolicy,
38-
maxEncryptedDataKeys
38+
maxEncryptedDataKeys,
3939
}
4040
return {
4141
decrypt: _decrypt.bind({}, clientOptions),

modules/decrypt-browser/test/decrypt.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('decrypt', () => {
4646
it('Precondition: _decrypt needs a valid commitmentPolicy.', async () => {
4747
await expect(
4848
_decrypt(
49-
{ commitmentPolicy: 'fake_policy' as any, maxEncryptedDataKeys: false},
49+
{ commitmentPolicy: 'fake_policy' as any, maxEncryptedDataKeys: false },
5050
{} as any,
5151
{} as any
5252
)

modules/decrypt-node/src/decrypt_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function buildDecrypt(
3131
const {
3232
commitmentPolicy = CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT,
3333
maxEncryptedDataKeys = false,
34-
utf8Sorting = false
34+
utf8Sorting = false,
3535
} = typeof options === 'string' ? { commitmentPolicy: options } : options
3636

3737
/* Precondition: node buildDecrypt needs a valid commitmentPolicy. */
@@ -45,7 +45,7 @@ export function buildDecrypt(
4545
const clientOptions: ClientOptions = {
4646
commitmentPolicy,
4747
maxEncryptedDataKeys,
48-
utf8Sorting
48+
utf8Sorting,
4949
}
5050
return {
5151
decryptUnsignedMessageStream: _decryptStream.bind(

modules/encrypt-browser/src/encrypt.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,12 @@ export async function _encrypt(
121121

122122
const { getSubtleEncrypt, keyCommitment } = await getEncryptInfo(messageId)
123123

124-
const maybeUtf8Sorting = utf8Sorting ?? false;
125-
126-
const serialize = serializeFactory(fromUtf8, {utf8Sorting: maybeUtf8Sorting})
127-
124+
const maybeUtf8Sorting = utf8Sorting ?? false
125+
126+
const serialize = serializeFactory(fromUtf8, {
127+
utf8Sorting: maybeUtf8Sorting,
128+
})
129+
128130
const messageHeader = serialize.buildMessageHeader({
129131
suite: material.suite,
130132
encryptedDataKeys: material.encryptedDataKeys,

modules/encrypt-browser/src/encrypt_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export function buildEncrypt(
2323
const {
2424
commitmentPolicy = CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT,
2525
maxEncryptedDataKeys = false,
26-
utf8Sorting = false
26+
utf8Sorting = false,
2727
} = typeof options === 'string' ? { commitmentPolicy: options } : options
2828

2929
/* Precondition: browser buildEncrypt needs a valid commitmentPolicy. */
@@ -37,7 +37,7 @@ export function buildEncrypt(
3737
const clientOptions: ClientOptions = {
3838
commitmentPolicy,
3939
maxEncryptedDataKeys,
40-
utf8Sorting
40+
utf8Sorting,
4141
}
4242
return {
4343
encrypt: _encrypt.bind({}, clientOptions),

modules/encrypt-node/src/encrypt_client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function buildEncrypt(
2727
const {
2828
commitmentPolicy = CommitmentPolicy.REQUIRE_ENCRYPT_REQUIRE_DECRYPT,
2929
maxEncryptedDataKeys = false,
30-
utf8Sorting = false
30+
utf8Sorting = false,
3131
} = typeof options === 'string' ? { commitmentPolicy: options } : options
3232

3333
/* Precondition: node buildEncrypt needs a valid commitmentPolicy. */
@@ -41,7 +41,7 @@ export function buildEncrypt(
4141
const clientOptions: ClientOptions = {
4242
commitmentPolicy,
4343
maxEncryptedDataKeys,
44-
utf8Sorting
44+
utf8Sorting,
4545
}
4646
return {
4747
encryptStream: _encryptStream.bind({}, clientOptions),

modules/encrypt-node/src/encrypt_stream.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function _encryptStream(
109109
'maxEncryptedDataKeys exceeded.'
110110
)
111111

112-
const maybeUtf8Sorting = utf8Sorting ?? false;
112+
const maybeUtf8Sorting = utf8Sorting ?? false
113113
const { getCipher, messageHeader, rawHeader, dispose, getSigner } =
114114
getEncryptionInfo(material, frameLength, maybeUtf8Sorting)
115115

@@ -145,7 +145,7 @@ export function getEncryptionInfo(
145145
) {
146146
const { getCipherInfo, dispose, getSigner } = getEncryptHelper(material)
147147
const { serializeMessageHeader, headerAuthIv, buildMessageHeader } =
148-
serializeFactory(fromUtf8, {utf8Sorting})
148+
serializeFactory(fromUtf8, { utf8Sorting })
149149
const { suite, encryptionContext, encryptedDataKeys } = material
150150
const { ivLength, messageFormat } = material.suite
151151

modules/encrypt-node/src/framed_encrypt_stream.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function getFramedEncryptStream(
106106
getCipher,
107107
isFinalFrame: false,
108108
suite,
109-
utf8Sorting
109+
utf8Sorting,
110110
})
111111

112112
// Reset frame state for next frame
@@ -129,7 +129,7 @@ export function getFramedEncryptStream(
129129
getCipher,
130130
isFinalFrame: true,
131131
suite,
132-
utf8Sorting
132+
utf8Sorting,
133133
})
134134

135135
this._flushEncryptFrame(encryptFrame)
@@ -210,7 +210,14 @@ type EncryptFrameInput = {
210210
}
211211

212212
export function getEncryptFrame(input: EncryptFrameInput): EncryptFrame {
213-
const { pendingFrame, messageHeader, getCipher, isFinalFrame, suite, utf8Sorting } = input
213+
const {
214+
pendingFrame,
215+
messageHeader,
216+
getCipher,
217+
isFinalFrame,
218+
suite,
219+
utf8Sorting,
220+
} = input
214221
const { sequenceNumber, contentLength, content } = pendingFrame
215222
const { frameLength, contentType, messageId } = messageHeader
216223
/* Precondition: The content length MUST correlate with the frameLength.
@@ -228,9 +235,9 @@ export function getEncryptFrame(input: EncryptFrameInput): EncryptFrame {
228235
isFinalFrame,
229236
})}`
230237
)
231-
const serialize = serializeFactory(fromUtf8, {utf8Sorting})
238+
const serialize = serializeFactory(fromUtf8, { utf8Sorting })
232239
const { finalFrameHeader, frameHeader } = serialize
233-
240+
234241
const frameIv = serialize.frameIv(suite.ivLength, sequenceNumber)
235242
const bodyHeader = Buffer.from(
236243
isFinalFrame

modules/encrypt-node/test/framed_encrypt_stream.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ describe('getEncryptFrame', () => {
149149
encryptedDataKeys: [],
150150
},
151151
suite,
152-
utf8Sorting: false
152+
utf8Sorting: false,
153153
}
154154

155155
expect(() => getEncryptFrame(inputFinalFrameToLarge)).to.throw(
@@ -176,7 +176,7 @@ describe('getEncryptFrame', () => {
176176
encryptedDataKeys: [],
177177
},
178178
suite,
179-
utf8Sorting: false
179+
utf8Sorting: false,
180180
}
181181

182182
// Make sure that it must be equal as long as we are here...

modules/kms-keyring-node/src/kms_hkeyring_node_helpers.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ import {
3333
PROVIDER_ID_HIERARCHY_AS_BYTES,
3434
} from './constants'
3535
import { BranchKeyIdSupplier } from '@aws-crypto/kms-keyring'
36-
import { serializeFactory, SerializeOptions, uuidv4Factory } from '@aws-crypto/serialize'
36+
import {
37+
serializeFactory,
38+
SerializeOptions,
39+
uuidv4Factory,
40+
} from '@aws-crypto/serialize'
3741

3842
export const stringToUtf8Bytes = (input: string): Buffer =>
3943
Buffer.from(input, 'utf-8')
@@ -45,9 +49,11 @@ const hexBytesToString = (input: Uint8Array): string =>
4549
Buffer.from(input).toString('hex')
4650
export const { uuidv4ToCompressedBytes, decompressBytesToUuidv4 } =
4751
uuidv4Factory(stringToHexBytes, hexBytesToString)
48-
export const utf8Sorting: SerializeOptions = {utf8Sorting: false}
49-
export const { serializeEncryptionContext } =
50-
serializeFactory(stringToUtf8Bytes, utf8Sorting)
52+
export const utf8Sorting: SerializeOptions = { utf8Sorting: false }
53+
export const { serializeEncryptionContext } = serializeFactory(
54+
stringToUtf8Bytes,
55+
utf8Sorting
56+
)
5157

5258
export function getBranchKeyId(
5359
{ branchKeyId, branchKeyIdSupplier }: IKmsHierarchicalKeyRingNode,

modules/kms-keyring-node/test/kms_hkeyring_node.helpers.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,10 @@ describe('KmsHierarchicalKeyRingNode: helpers', () => {
157157
).to.deep.equal(branchKeyVersionAsBytes)
158158

159159
startIdx += branchKeyVersionAsBytes.length
160-
const expectedAad = serializeEncryptionContext(encryptionContext, utf8Sorting).slice(2)
160+
const expectedAad = serializeEncryptionContext(
161+
encryptionContext,
162+
utf8Sorting
163+
).slice(2)
161164
expect(wrappedAad.subarray(startIdx)).to.deep.equal(expectedAad)
162165
})
163166
})

modules/raw-aes-keyring-browser/src/raw_aes_keyring_browser.ts

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ import {
1818
importForWebCryptoDecryptionMaterial,
1919
AwsEsdkJsCryptoKey,
2020
} from '@aws-crypto/material-management-browser'
21-
import { serializeFactory, concatBuffers, SerializeOptions } from '@aws-crypto/serialize'
21+
import {
22+
serializeFactory,
23+
concatBuffers,
24+
SerializeOptions,
25+
} from '@aws-crypto/serialize'
2226
import {
2327
_onEncrypt,
2428
_onDecrypt,
@@ -76,18 +80,22 @@ export class RawAesKeyringWebCrypto extends KeyringWebCrypto {
7680
keyName,
7781
flags: KeyringTraceFlag.WRAPPING_KEY_GENERATED_DATA_KEY,
7882
})
79-
80-
const serializeOptions: SerializeOptions= {utf8Sorting: false}
81-
const { serializeEncryptionContext } = serializeFactory(fromUtf8, serializeOptions)
83+
84+
const serializeOptions: SerializeOptions = { utf8Sorting: false }
85+
const { serializeEncryptionContext } = serializeFactory(
86+
fromUtf8,
87+
serializeOptions
88+
)
8289
const _wrapKey = async (material: WebCryptoEncryptionMaterial) => {
8390
/* The AAD section is uInt16BE(length) + AAD
8491
* see: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/message-format.html#header-aad
8592
* However, the RAW Keyring wants _only_ the ADD.
8693
* So, I just slice off the length.
8794
*/
88-
const aad = serializeEncryptionContext(material.encryptionContext, serializeOptions).slice(
89-
2
90-
)
95+
const aad = serializeEncryptionContext(
96+
material.encryptionContext,
97+
serializeOptions
98+
).slice(2)
9199
const { keyNamespace, keyName } = this
92100

93101
return aesGcmWrapKey(
@@ -108,9 +116,10 @@ export class RawAesKeyringWebCrypto extends KeyringWebCrypto {
108116
* However, the RAW Keyring wants _only_ the ADD.
109117
* So, I just slice off the length.
110118
*/
111-
const aad = serializeEncryptionContext(material.encryptionContext, serializeOptions).slice(
112-
2
113-
)
119+
const aad = serializeEncryptionContext(
120+
material.encryptionContext,
121+
serializeOptions
122+
).slice(2)
114123
const { keyNamespace, keyName } = this
115124

116125
return aesGcmUnwrapKey(

modules/raw-aes-keyring-node/src/raw_aes_keyring_node.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ import {
1414
NodeAlgorithmSuite,
1515
} from '@aws-crypto/material-management-node'
1616
import { randomBytes, createCipheriv, createDecipheriv } from 'crypto'
17-
import { serializeFactory, concatBuffers, SerializeOptions} from '@aws-crypto/serialize'
17+
import {
18+
serializeFactory,
19+
concatBuffers,
20+
SerializeOptions,
21+
} from '@aws-crypto/serialize'
1822
import {
1923
_onEncrypt,
2024
_onDecrypt,
@@ -28,7 +32,9 @@ import {
2832
const fromUtf8 = (input: string) => Buffer.from(input, 'utf8')
2933
const toUtf8 = (input: Uint8Array) =>
3034
Buffer.from(input.buffer, input.byteOffset, input.byteLength).toString('utf8')
31-
const { serializeEncryptionContext } = serializeFactory(fromUtf8, {utf8Sorting: false})
35+
const { serializeEncryptionContext } = serializeFactory(fromUtf8, {
36+
utf8Sorting: false,
37+
})
3238
const { rawAesEncryptedDataKey } = rawAesEncryptedDataKeyFactory(
3339
toUtf8,
3440
fromUtf8
@@ -67,15 +73,16 @@ export class RawAesKeyringNode extends KeyringNode {
6773
})
6874

6975
// default will be false for the first release and then flipped to true
70-
const serializeOptions: SerializeOptions= {utf8Sorting: false}
76+
const serializeOptions: SerializeOptions = { utf8Sorting: false }
7177
const _wrapKey = async (material: NodeEncryptionMaterial) => {
7278
/* The AAD section is uInt16BE(length) + AAD
7379
* see: https://docs.aws.amazon.com/encryption-sdk/latest/developer-guide/message-format.html#header-aad
7480
* However, the RAW Keyring wants _only_ the ADD.
7581
* So, I just slice off the length.
7682
*/
7783
const { buffer, byteOffset, byteLength } = serializeEncryptionContext(
78-
material.encryptionContext, serializeOptions
84+
material.encryptionContext,
85+
serializeOptions
7986
).slice(2)
8087
const aad = Buffer.from(buffer, byteOffset, byteLength)
8188
const { keyNamespace, keyName } = this

0 commit comments

Comments
 (0)