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

Provide native implementations using traits instead of static methods #318

Open
robin-aws opened this issue May 13, 2020 · 0 comments
Open

Comments

@robin-aws
Copy link
Contributor

robin-aws commented May 13, 2020

For example, RSA encryption is currently declared in Dafny as a module-level method with no body and the {:extern} attribute:

module {:extern "RSAEncryption"} RSAEncryption {
  ...
  method {:extern "RSAEncryption.RSA", "EncryptExtern"} EncryptExtern(padding: PaddingMode, publicKey: seq<uint8>,
                                                                      plaintextData: seq<uint8>)
      returns (res: Result<seq<uint8>>)
    requires |publicKey| > 0
    requires |plaintextData| > 0
...
}

This makes it impossible to compile the Dafny ESDK by itself, since the C# compiler will complain about the missing implementation. Instead, we can provide this functionality through a trait which is provided as an extra method argument and/or class/datatype field as needed:

trait {:extern "RSAImplementation"} RSAImplementation {
  ...
  method {:extern "RSAEncryption.RSA", "EncryptExtern"} EncryptExtern(padding: PaddingMode, publicKey: seq<uint8>,
                                                                      plaintextData: seq<uint8>)
      returns (res: Result<seq<uint8>>)
    requires |publicKey| > 0
    requires |plaintextData| > 0
...
}

Wrapping ESDKs like the .NET ESDK would provide the native implementation of such traits, and instantiate them as part of the initialization process of the library. This initialization would occur through either static initialization methods or as part of creating a top-level object like Java's AwsCrypto object. Since Dafny does not (yet) support static objects, I lean towards the second option.

This will also simplify the surface area in scope for extern soundness (#165), since cross-language interfacing will be mostly restricted to traits (it will still be necessary to expose static methods for invocation from external code).

@acioc acioc added this to the Future Backlog milestone May 26, 2020
@farleyb-amazon farleyb-amazon removed this from the Future Backlog milestone May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants