Skip to content

Commit 2a7c741

Browse files
committed
test: Adds comment about EC prefix behavior difference between dafny and JavaScript implementation
1 parent 23e6fdc commit 2a7c741

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

modules/branch-keystore-node/src/branch_keystore_helpers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ function constructCustomEncryptionContext(
349349
//# Also, the value in the [encryption context](./structures.md#encryption-context-3) for this key
350350
//# MUST equal the value in the authenticated encryption context
351351
//# for the constructed key.
352+
// NOTE: The Dafny implementation strips the `aws-crypto-ec:` prefix
353+
// from keys before returning (see ExtractCustomEncryptionContext in Structure.dfy).
352354
for (const [key, value] of Object.entries(authenticatedEncryptionContext)) {
353355
if (key.startsWith(CUSTOM_ENCRYPTION_CONTEXT_FIELD_PREFIX)) {
354356
customEncryptionContext[key] = value

modules/branch-keystore-node/test/branch_keystore.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,9 @@ describe('Test Branch keystore', () => {
979979
const material = await keyStore.getActiveBranchKey(customId)
980980
expect(material.branchKey().length).to.equal(32)
981981

982-
// Custom encryption context must be preserved
982+
// Custom encryption context must be preserved.
983+
// NOTE: Unlike the Dafny implementation, the JS SDK currently returns
984+
// keys with the `aws-crypto-ec:` prefix.
983985
expect(material.encryptionContext).to.have.property(
984986
'aws-crypto-ec:department',
985987
'test'
@@ -1006,6 +1008,8 @@ describe('Test Branch keystore', () => {
10061008
})
10071009

10081010
// 2. Retrieve the active key and verify EC
1011+
// NOTE: Unlike the Dafny implementation, the JS SDK currently returns
1012+
// keys with the `aws-crypto-ec:` prefix.
10091013
const v1 = await keyStore.getActiveBranchKey(branchKeyIdentifier)
10101014
const v1Version = v1.branchKeyVersion.toString('utf8')
10111015
expect(v1.branchKey().length).to.equal(32)
@@ -1026,6 +1030,8 @@ describe('Test Branch keystore', () => {
10261030
const v2Version = v2.branchKeyVersion.toString('utf8')
10271031
expect(v2.branchKey().length).to.equal(32)
10281032
expect(v2Version).to.not.equal(v1Version)
1033+
// NOTE: Unlike the Dafny implementation, the JS SDK currently returns
1034+
// keys with the `aws-crypto-ec:` prefix.
10291035
expect(v2.encryptionContext).to.have.property(
10301036
'aws-crypto-ec:department',
10311037
'engineering'
@@ -1042,10 +1048,16 @@ describe('Test Branch keystore', () => {
10421048
)
10431049
expect(oldMaterial.branchKey().length).to.equal(32)
10441050
expect(oldMaterial.branchKeyIdentifier).to.equal(branchKeyIdentifier)
1051+
// NOTE: Unlike the Dafny implementation, the JS SDK currently returns
1052+
// keys with the `aws-crypto-ec:` prefix.
10451053
expect(oldMaterial.encryptionContext).to.have.property(
10461054
'aws-crypto-ec:department',
10471055
'engineering'
10481056
)
1057+
expect(oldMaterial.encryptionContext).to.have.property(
1058+
'aws-crypto-ec:project',
1059+
'lifecycle'
1060+
)
10491061
})
10501062
})
10511063
})

0 commit comments

Comments
 (0)