Skip to content

Commit 47b8f0d

Browse files
seebeesjosecorella
andauthored
Apply suggestions from code review
Co-authored-by: José Corella <[email protected]>
1 parent 7fb3bba commit 47b8f0d

File tree

5 files changed

+10
-41
lines changed

5 files changed

+10
-41
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
import { unmarshall } from '@aws-sdk/util-dynamodb'
1212
import { BranchKeyItem, BranchKeyRecord } from './branch_keystore_structures'
1313
import { EncryptedHierarchicalKey, BranchKeyEncryptionContext } from './types'
14-
// import { IBranchKeyStoreNode } from './branch_keystore'
1514
import { DecryptCommand } from '@aws-sdk/client-kms'
1615
import { KmsKeyConfig } from './kms_config'
1716
import {
@@ -71,7 +70,7 @@ export async function getBranchKeyItem(
7170
// error out if there is not Item field (record not found)
7271
needs(
7372
responseItem,
74-
`A branch key record with ${PARTITION_KEY}=${partitionValue} and ${SORT_KEY}=${sortValue} was not found in DynamoDB`
73+
`A branch key record with ${PARTITION_KEY}=${partitionValue} and ${SORT_KEY}=${sortValue} was not found in the DynamoDB table ${ddbTableName}.`
7574
)
7675
// at this point, we got back a record so convert the DDB response item into
7776
// a more JS-friendly object

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ export class DynamoDBKeyStorage implements IBranchKeyStorage {
5858

5959
needs(
6060
typeof logicalKeyStoreName === 'string',
61-
'DDB table name must be a string'
61+
'Logical Key Store name must be a string'
6262
)
63-
63+
needs(logicalKeyStoreName, 'Logical Key Store name required')
6464
/* Precondition: DDB client must be a DynamoDBClient */
6565
needs(
6666
ddbClient instanceof DynamoDBClient,
@@ -154,7 +154,10 @@ export class DynamoDBKeyStorage implements IBranchKeyStorage {
154154

155155
//= aws-encryption-sdk-specification/framework/key-store/dynamodb-key-storage.md#getencryptedbranchkeyversion
156156
//# The returned EncryptedHierarchicalKey MUST have the same identifier as the input.
157-
needs(encrypted.branchKeyId == branchKeyId, 'Unexpected branch key id.')
157+
needs(
158+
encrypted.branchKeyId == branchKeyId,
159+
'Unexpected branch key id. Expected ${branchKeyId}, found ${encrypted.branchKeyId}'
160+
)
158161

159162
//= aws-encryption-sdk-specification/framework/key-store/dynamodb-key-storage.md#getencryptedbranchkeyversion
160163
//# The returned EncryptedHierarchicalKey MUST have the same version as the input.

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ import {
4242
import { DynamoDBKeyStorage } from '../src/dynamodb_key_storage'
4343
import {
4444
EncryptedHierarchicalKey,
45-
// ActiveKeyEncryptionContext,
46-
// VersionKeyEncryptionContext,
47-
// BranchKeyVersionType,
4845
} from '../src/types'
4946

5047
const VALID_CUSTOM_ENCRYPTION_CONTEXT_KV_PAIRS = {

modules/example-node/hkr-demo/hkr.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const { encrypt, decrypt } = buildClient(
1818
const MAX_INPUT_LENGTH = 20
1919
const MIN_INPUT_LENGTH = 15
2020
const PURPLE_LOG = '\x1b[35m%s\x1b[0m'
21-
const YELLO_LOG = '\x1b[33m%s\x1b[0m'
21+
const YELLOW_LOG = '\x1b[33m%s\x1b[0m'
2222
const GREEN_LOG = '\x1b[32m%s\x1b[0m'
2323
const RED_LOG = '\x1b[31m%s\x1b[0m'
2424

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

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@ import {
1919
createHash,
2020
randomBytes,
2121
} from 'crypto'
22-
// import { uInt32BE } from '@aws-crypto/serialize'
2322
import { CryptographicMaterialsCache } from '@aws-crypto/cache-material'
2423
import { kdfCounterMode } from '@aws-crypto/kdf-ctr-mode-node'
2524
import {
26-
// ACTIVE_AS_BYTES,
2725
CACHE_ENTRY_ID_DIGEST_ALGORITHM,
28-
// CACHE_ENTRY_ID_LENGTH,
2926
CIPHERTEXT_STRUCTURE,
3027
DECRYPT_FLAGS,
3128
DERIVED_BRANCH_KEY_LENGTH,
@@ -50,8 +47,6 @@ export const { uuidv4ToCompressedBytes, decompressBytesToUuidv4 } =
5047
uuidv4Factory(stringToHexBytes, hexBytesToString)
5148
export const { serializeEncryptionContext } =
5249
serializeFactory(stringToUtf8Bytes)
53-
// const stringToAsciiBytes = (input: string): Buffer =>
54-
// Buffer.from(input, 'ascii')
5550

5651
export function getBranchKeyId(
5752
{ branchKeyId, branchKeyIdSupplier }: IKmsHierarchicalKeyRingNode,
@@ -185,33 +180,8 @@ export function getCacheEntryId(
185180
])
186181
}
187182

188-
// const entryInfo = versionAsBytes
189-
// ? Buffer.concat([
190-
// RESOURCE_ID,
191-
// NULL_BYTE,
192-
// DECRYPTION_SCOPE,
193-
// NULL_BYTE,
194-
// partitionId,
195-
// NULL_BYTE,
196-
// logicalKeyStoreName,
197-
// NULL_BYTE,
198-
// branchKeyIdAsBytes,
199-
// NULL_BYTE,
200-
// versionAsBytes,
201-
// ])
202-
// : Buffer.concat([
203-
// RESOURCE_ID,
204-
// NULL_BYTE,
205-
// ENCRYPTION_SCOPE,
206-
// NULL_BYTE,
207-
// partitionId,
208-
// NULL_BYTE,
209-
// logicalKeyStoreName,
210-
// NULL_BYTE,
211-
// branchKeyIdAsBytes,
212-
// ])
213-
214-
// encrypt the branch key id buffer with sha512
183+
184+
// hash the branch key id buffer with sha512
215185
return createHash(CACHE_ENTRY_ID_DIGEST_ALGORITHM)
216186
.update(entryInfo)
217187
.digest()

0 commit comments

Comments
 (0)