Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: make const policy an extern #1587

Merged
merged 11 commits into from
Feb 3, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module {:extern "software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencry
static method {:extern} Build(encryptorConfig: Types.DynamoDbItemEncryptorConfig)
returns (output: Result<Option<InternalLegacyOverride>, Types.Error>)

const policy: DDBE.LegacyPolicy
const {:extern} policy: DDBE.LegacyPolicy

method {:extern} EncryptItem(input: Types.EncryptItemInput)
returns (output: Result<Types.EncryptItemOutput, Types.Error>)
Expand Down
13 changes: 12 additions & 1 deletion DynamoDbEncryption/runtimes/net/Extern/InternalLegacyConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ namespace software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.in

public partial class InternalLegacyOverride
{

public software.amazon.cryptography.dbencryptionsdk.dynamodb.internaldafny.types._ILegacyPolicy _policy
Copy link
Member Author

@rishav-karanjit rishav-karanjit Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tried following before reaching to this as solution:

  • Directly add a constant _policy in the class: This does not work because it should also be initialized with a constant in RHS and create_FORBID__LEGACY__ENCRYPT__FORBID__LEGACY__DECRYPT is not a constant.
  • Add a default constructor: We could have added a _policy and initialize it in a default constructor but this will not work because dafny transpiles a default constructor into class InternalLegacyOverride and this will cause conflict.

So, the best solution here is to always return FORBID__LEGACY__ENCRYPT__FORBID__LEGACY__DECRYPT from the getter. This is the only place, this variable is going to be used. However, technically this variable is never used because config.internalLegacyOverride.Some? is always false for .NET (and Rust) because they don't support legacy

{
get => software.amazon.cryptography.dbencryptionsdk.dynamodb.internaldafny.types.LegacyPolicy.create_FORBID__LEGACY__ENCRYPT__FORBID__LEGACY__DECRYPT();
set { }
}
public software.amazon.cryptography.dbencryptionsdk.dynamodb.internaldafny.types._ILegacyPolicy policy
{
get
{
return this._policy;
}
}
public static Wrappers_Compile._IResult<
Wrappers_Compile._IOption<InternalLegacyOverride>,
_IError
Expand Down
3 changes: 3 additions & 0 deletions DynamoDbEncryption/runtimes/rust/src/software_externs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub mod software {
}

impl InternalLegacyOverride {
pub fn policy(&self) -> Rc<LegacyPolicy> {
self.r#__i_policy.clone()
}
pub fn Build(
config: &Rc<crate::software::amazon::cryptography::dbencryptionsdk::dynamodb::itemencryptor::internaldafny::types::DynamoDbItemEncryptorConfig>,
) -> Rc<
Expand Down
Loading