|
| 1 | +// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +include "../Model/AwsCryptographyDynamoDbEncryptionTypesWrapped.dfy" |
| 5 | +include "../../../../DynamoDbEncryption/dafny/DynamoDbItemEncryptor/src/Index.dfy" |
| 6 | + |
| 7 | +module {:extern} CreateWrappedItemEncryptor { |
| 8 | + import opened Wrappers |
| 9 | + import AwsCryptographyDbEncryptionSdkDynamoDbTypes |
| 10 | + import ENC = AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorTypes |
| 11 | + import DynamoDbItemEncryptor |
| 12 | + import Operations = AwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorOperations |
| 13 | + |
| 14 | + // The `ensures` clause is copy-pasted from the DynamoDbItemEncryptor client method's `ensures` clause. |
| 15 | + method {:extern} CreateWrappedItemEncryptor(config: ENC.DynamoDbItemEncryptorConfig) |
| 16 | + returns (output: Result<ENC.IDynamoDbItemEncryptorClient, ENC.Error>) |
| 17 | + requires config.keyring.Some? ==> |
| 18 | + config.keyring.value.ValidState() |
| 19 | + requires config.cmm.Some? ==> |
| 20 | + config.cmm.value.ValidState() |
| 21 | + requires config.legacyOverride.Some? ==> |
| 22 | + config.legacyOverride.value.encryptor.ValidState() |
| 23 | + modifies if config.keyring.Some? then |
| 24 | + config.keyring.value.Modifies |
| 25 | + else {} |
| 26 | + modifies if config.cmm.Some? then |
| 27 | + config.cmm.value.Modifies |
| 28 | + else {} |
| 29 | + modifies if config.legacyOverride.Some? then |
| 30 | + config.legacyOverride.value.encryptor.Modifies |
| 31 | + else {} |
| 32 | + ensures output.Success? ==> |
| 33 | + && output.value is DynamoDbItemEncryptor.DynamoDbItemEncryptorClient |
| 34 | + && fresh(output.value) |
| 35 | + && fresh(output.value.History) |
| 36 | + && output.value.ValidState() |
| 37 | + && var rconfig := (output.value as DynamoDbItemEncryptor.DynamoDbItemEncryptorClient).config; |
| 38 | + && fresh(output.value.Modifies - Operations.ModifiesInternalConfig(rconfig)) |
| 39 | + && rconfig.logicalTableName == config.logicalTableName |
| 40 | + && rconfig.partitionKeyName == config.partitionKeyName |
| 41 | + && rconfig.sortKeyName == config.sortKeyName |
| 42 | + && rconfig.attributeActionsOnEncrypt == config.attributeActionsOnEncrypt |
| 43 | + && rconfig.allowedUnsignedAttributes == config.allowedUnsignedAttributes |
| 44 | + && rconfig.allowedUnsignedAttributePrefix == config.allowedUnsignedAttributePrefix |
| 45 | + && rconfig.algorithmSuiteId == config.algorithmSuiteId |
| 46 | + |
| 47 | + //= specification/dynamodb-encryption-client/ddb-table-encryption-config.md#attribute-actions |
| 48 | + //= type=implication |
| 49 | + //# The [Key Action](#key-action) |
| 50 | + //# MUST be configured to the partition attribute and, if present, sort attribute. |
| 51 | + && rconfig.version == Operations.VersionFromActions(config.attributeActionsOnEncrypt) |
| 52 | + && config.partitionKeyName in config.attributeActionsOnEncrypt |
| 53 | + && config.attributeActionsOnEncrypt[config.partitionKeyName] == Operations.KeyActionFromVersion(rconfig.version) |
| 54 | + && (config.sortKeyName.Some? ==> |
| 55 | + && config.sortKeyName.value in config.attributeActionsOnEncrypt |
| 56 | + && config.attributeActionsOnEncrypt[config.sortKeyName.value] == Operations.KeyActionFromVersion(rconfig.version)) |
| 57 | + |
| 58 | + //= specification/dynamodb-encryption-client/ddb-table-encryption-config.md#plaintext-policy |
| 59 | + //# If not specified, encryption and decryption MUST behave according to `FORBID_PLAINTEXT_WRITE_FORBID_PLAINTEXT_READ`. |
| 60 | + ensures |
| 61 | + && output.Success? |
| 62 | + && config.plaintextOverride.None? |
| 63 | + ==> |
| 64 | + && var config := (output.value as DynamoDbItemEncryptor.DynamoDbItemEncryptorClient).config; |
| 65 | + && config.plaintextOverride.FORBID_PLAINTEXT_WRITE_FORBID_PLAINTEXT_READ? |
| 66 | +} |
0 commit comments