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

fix: Move Java helper methods out of extern class #855

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import software.amazon.cryptography.primitives.internaldafny.types.Error;
import software.amazon.cryptography.primitives.model.AwsCryptographicPrimitivesError;

public class HMac extends _ExternBase_HMac {
public class HMac extends _ExternBase___default {

private String algorithm;
private Mac hmac;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ def Digest(input: HMacInput):
output = hmac.GetResult()
return Wrappers.Result_Success(_dafny.Seq(output))

# Extend generated class
class HMac(aws_cryptography_primitives.internaldafny.generated.HMAC.HMac):
class HMac:

@staticmethod
def Build(digest):
Expand Down
16 changes: 9 additions & 7 deletions AwsCryptographyPrimitives/src/HKDF/HMAC.dfy
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,7 @@ module {:options "-functionSyntax:4"} {:extern "HMAC"} HMAC {
// since their calling pattern is different between different versions of Dafny
// (i.e. after 4.2, explicit type descriptors are required).

static function CreateHMacSuccess(hmac: HMac): Result<HMac, Types.Error> {
Success(hmac)
}

static function CreateHMacFailure(error: Types.Error): Result<HMac, Types.Error> {
Failure(error)
}
}

// HMAC Digest is safe to make a Dafny function
Expand All @@ -78,11 +72,19 @@ module {:options "-functionSyntax:4"} {:extern "HMAC"} HMAC {
: ( output: Result<seq<uint8>, Types.Error> )
ensures output.Success? ==> |output.value| == HashDigest.Length(input.digestAlgorithm)

// The next two functions are for the benefit of the extern implementation to call,
// The following functions are for the benefit of the extern implementation to call,
// avoiding direct references to generic datatype constructors
// since their calling pattern is different between different versions of Dafny
// (i.e. after 4.2, explicit type descriptors are required).

function CreateHMacSuccess(hmac: HMac): Result<HMac, Types.Error> {
Success(hmac)
}

function CreateHMacFailure(error: Types.Error): Result<HMac, Types.Error> {
Failure(error)
}

function CreateDigestSuccess(bytes: seq<uint8>): Result<seq<uint8>, Types.Error> {
Success(bytes)
}
Expand Down
Loading