Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test: Adds comment about EC prefix behavior difference between dafny …
…and JavaScript implementation
  • Loading branch information
sharmabikram committed Mar 19, 2026
commit f9433af5053c44798b67648ccfc615ea8ccc2938
2 changes: 2 additions & 0 deletions modules/branch-keystore-node/src/branch_keystore_helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,8 @@ function constructCustomEncryptionContext(
//# Also, the value in the [encryption context](./structures.md#encryption-context-3) for this key
//# MUST equal the value in the authenticated encryption context
//# for the constructed key.
// NOTE: The Dafny implementation strips the `aws-crypto-ec:` prefix
// from keys before returning (see ExtractCustomEncryptionContext in Structure.dfy).
for (const [key, value] of Object.entries(authenticatedEncryptionContext)) {
if (key.startsWith(CUSTOM_ENCRYPTION_CONTEXT_FIELD_PREFIX)) {
customEncryptionContext[
Expand Down
14 changes: 13 additions & 1 deletion modules/branch-keystore-node/test/branch_keystore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,9 @@ describe('Test Branch keystore', () => {
const material = await keyStore.getActiveBranchKey(customId)
expect(material.branchKey().length).to.equal(32)

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

// 2. Retrieve the active key and verify EC
// NOTE: Unlike the Dafny implementation, the JS SDK currently returns
// keys with the `aws-crypto-ec:` prefix.
const v1 = await keyStore.getActiveBranchKey(branchKeyIdentifier)
const v1Version = v1.branchKeyVersion.toString('utf8')
expect(v1.branchKey().length).to.equal(32)
Expand All @@ -1026,6 +1030,8 @@ describe('Test Branch keystore', () => {
const v2Version = v2.branchKeyVersion.toString('utf8')
expect(v2.branchKey().length).to.equal(32)
expect(v2Version).to.not.equal(v1Version)
// NOTE: Unlike the Dafny implementation, the JS SDK currently returns
// keys with the `aws-crypto-ec:` prefix.
expect(v2.encryptionContext).to.have.property(
'aws-crypto-ec:department',
'engineering'
Expand All @@ -1042,10 +1048,16 @@ describe('Test Branch keystore', () => {
)
expect(oldMaterial.branchKey().length).to.equal(32)
expect(oldMaterial.branchKeyIdentifier).to.equal(branchKeyIdentifier)
// NOTE: Unlike the Dafny implementation, the JS SDK currently returns
// keys with the `aws-crypto-ec:` prefix.
expect(oldMaterial.encryptionContext).to.have.property(
'aws-crypto-ec:department',
'engineering'
)
expect(oldMaterial.encryptionContext).to.have.property(
'aws-crypto-ec:project',
'lifecycle'
)
})
})
})