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: add rust support #1376

Merged
merged 96 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
96 commits
Select commit Hold shift + click to select a range
b4f7504
feat: add rust support
ajewellamz Sep 17, 2024
c7ca894
m
ajewellamz Sep 17, 2024
5737a2a
m
ajewellamz Sep 17, 2024
639edcd
m
ajewellamz Sep 17, 2024
a7a7014
m
ajewellamz Sep 17, 2024
a06ca96
m
ajewellamz Sep 18, 2024
e87ce13
m
ajewellamz Sep 18, 2024
6b853b8
m
ajewellamz Sep 18, 2024
fbccc50
m
ajewellamz Sep 18, 2024
8c2140e
Missing local service dependencies, remove externs_utf8.rs
robin-aws Sep 19, 2024
4fbd767
m
ajewellamz Sep 19, 2024
6bd7ef5
m
ajewellamz Sep 19, 2024
5f48deb
m
ajewellamz Sep 19, 2024
35662f0
m
ajewellamz Sep 19, 2024
0f8cfcd
m
ajewellamz Sep 19, 2024
4897b76
m
ajewellamz Sep 19, 2024
dab805e
m
ajewellamz Sep 19, 2024
b6b3d02
m
ajewellamz Sep 19, 2024
088a7dc
Merge branch 'main' into ajewell/rust
ajewellamz Sep 19, 2024
02d7b0a
m
ajewellamz Sep 19, 2024
7ab9b08
m
ajewellamz Sep 20, 2024
7933a2c
m
ajewellamz Sep 20, 2024
a7c313f
m
ajewellamz Sep 20, 2024
8784720
m
ajewellamz Sep 20, 2024
e33e92f
m
ajewellamz Sep 20, 2024
3e37a0c
create release directory
ajewellamz Sep 20, 2024
4e0ad55
m
ajewellamz Sep 20, 2024
84823f8
m
ajewellamz Sep 20, 2024
a92702b
m
ajewellamz Sep 20, 2024
05de400
m
ajewellamz Sep 20, 2024
21e8529
Merge branch 'main' into ajewell/rust
ajewellamz Sep 20, 2024
dbb6c19
m
ajewellamz Sep 20, 2024
698f501
m
ajewellamz Sep 20, 2024
73f0c89
Merge branch 'main' into ajewell/rust
ajewellamz Sep 20, 2024
07de35f
m
ajewellamz Sep 20, 2024
dd1a953
m
ajewellamz Sep 20, 2024
0f9a45f
m
ajewellamz Sep 21, 2024
a216ef8
m
ajewellamz Sep 21, 2024
99ac9fa
m
ajewellamz Sep 21, 2024
08e30b8
m
ajewellamz Sep 23, 2024
36aea0e
m
ajewellamz Sep 23, 2024
00a9c6b
m
ajewellamz Sep 23, 2024
a2662a6
m
ajewellamz Sep 23, 2024
f790f4f
m
ajewellamz Sep 23, 2024
b2bce62
m
ajewellamz Sep 24, 2024
f1cb45d
m
ajewellamz Sep 24, 2024
89bae50
m
ajewellamz Sep 24, 2024
6ed725e
m
ajewellamz Sep 27, 2024
0aca980
m
ajewellamz Sep 27, 2024
d08ddc4
m
ajewellamz Sep 27, 2024
81c0e6f
m
ajewellamz Oct 11, 2024
ef1e678
m
ajewellamz Oct 21, 2024
c152632
Merge branch 'main' into ajewell/rust
ajewellamz Oct 21, 2024
f97abc1
m
ajewellamz Oct 22, 2024
0c613ce
m
ajewellamz Oct 22, 2024
e2b46f3
m
ajewellamz Oct 22, 2024
1629332
m
ajewellamz Oct 22, 2024
58ec6c7
m
ajewellamz Oct 22, 2024
270de7a
m
ajewellamz Oct 25, 2024
5cc7e89
m
ajewellamz Oct 25, 2024
66940ec
m
ajewellamz Oct 25, 2024
05a5085
m
ajewellamz Nov 13, 2024
962c6ff
rebuild release
ajewellamz Nov 13, 2024
3d02023
m
ajewellamz Nov 15, 2024
28ab9c3
m
ajewellamz Nov 15, 2024
cc0dea2
m
ajewellamz Nov 18, 2024
fc423f4
m
ajewellamz Nov 18, 2024
96091d8
Merge branch 'main' into ajewell/rust
ajewellamz Nov 18, 2024
f034d5a
m
ajewellamz Nov 18, 2024
7572e0d
m
ajewellamz Nov 18, 2024
b2c1eb5
m
ajewellamz Nov 18, 2024
efb13f8
m
ajewellamz Nov 18, 2024
d09d11e
m
ajewellamz Nov 18, 2024
7a9c1ba
m
ajewellamz Nov 18, 2024
c364570
m
ajewellamz Nov 18, 2024
c1ee22f
m
ajewellamz Nov 18, 2024
45ee202
m
ajewellamz Nov 18, 2024
825b69d
fix(Java): DummySubsetType
texastony Nov 20, 2024
a14efdd
m
ajewellamz Nov 20, 2024
0a3eba1
m
ajewellamz Nov 21, 2024
40b0b47
m
ajewellamz Nov 21, 2024
d638ee9
chore(examples): Run Rust examples in CI (#1477)
RitvikKapila Nov 22, 2024
ebf6564
m
ajewellamz Nov 25, 2024
1dcbb06
m
ajewellamz Nov 25, 2024
01fdac4
m
ajewellamz Nov 25, 2024
9410dac
Merge branch 'main' into ajewell/rust
ajewellamz Dec 2, 2024
0b9e808
m
ajewellamz Dec 2, 2024
a2b153c
Merge branch 'ajewell/rust' of github.com:aws/aws-database-encryption…
ajewellamz Dec 2, 2024
b62a2d1
m
ajewellamz Dec 2, 2024
8042fd3
m
ajewellamz Dec 2, 2024
659e5cc
m
ajewellamz Dec 2, 2024
6f3f613
m
ajewellamz Dec 3, 2024
a94fc54
m
ajewellamz Dec 3, 2024
3a26afc
m
ajewellamz Dec 3, 2024
adc17f0
pr feedback
ajewellamz Dec 3, 2024
2302508
m
ajewellamz Dec 3, 2024
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
5 changes: 5 additions & 0 deletions .github/workflows/daily_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ jobs:
uses: ./.github/workflows/ci_test_net.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
daily-ci-rust:
needs: getVersion
uses: ./.github/workflows/library_rust_tests.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
daily-ci-net-test-vectors:
needs: getVersion
uses: ./.github/workflows/ci_test_vector_net.yml
Expand Down
117 changes: 117 additions & 0 deletions .github/workflows/library_rust_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# This workflow performs tests in Rust.
name: Library Rust tests

on:
workflow_call:
inputs:
dafny:
description: "The Dafny version to run"
required: true
type: string
regenerate-code:
description: "Regenerate code using smithy-dafny"
required: false
default: false
type: boolean

jobs:
testRust:
strategy:
fail-fast: false
matrix:
library: [DynamoDbEncryption, TestVectors]
# removed windows-latest because somehow it can't build aws-lc in CI
os: [ubuntu-latest, macos-13]
runs-on: ${{ matrix.os }}
permissions:
id-token: write
contents: read
env:
RUST_MIN_STACK: 104857600
steps:
- name: Support longpaths on Git checkout
run: |
git config --global core.longpaths true
- uses: actions/checkout@v3
- name: Init Submodules
shell: bash
run: |
git submodule update --init --recursive submodules/smithy-dafny
git submodule update --init --recursive submodules/MaterialProviders

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: us-west-2
role-to-assume: arn:aws:iam::370957321024:role/GitHub-CI-DDBEC-Dafny-Role-us-west-2
role-session-name: DDBEC-Dafny-Rust-Tests

- name: Setup Rust Toolchain for GitHub CI
uses: actions-rust-lang/[email protected]
with:
components: rustfmt
# uncomment this after Rust formatter works
# - name: Rustfmt Check
# uses: actions-rust-lang/rustfmt@v1

- name: Setup Dafny
uses: dafny-lang/[email protected]
with:
dafny-version: nightly-latest

# Remove this after the formatting in Rust starts working
- name: smithy-dafny Rust hacks
shell: bash
run: |
if [ "$RUNNER_OS" == "macOS" ]; then
sed -i '' 's|rustfmt --edition 2021 runtimes/rust/src/implementation_from_dafny.rs|#&|' submodules/smithy-dafny/SmithyDafnyMakefile.mk
else
sed -i 's|rustfmt --edition 2021 runtimes/rust/src/implementation_from_dafny.rs|#&|' submodules/smithy-dafny/SmithyDafnyMakefile.mk
fi

- name: Setup Java 17 for codegen
uses: actions/setup-java@v3
with:
distribution: "corretto"
java-version: "17"

- name: Setup NASM for Windows (aws-lc-sys)
if: matrix.os == 'windows-latest'
uses: ilammy/setup-nasm@v1

- name: Install Smithy-Dafny codegen dependencies
uses: ./.github/actions/install_smithy_dafny_codegen_dependencies

- name: Run make polymorph_rust
shell: bash
working-directory: ./${{ matrix.library }}
run: |
make polymorph_rust

- name: Compile ${{ matrix.library }} implementation
shell: bash
working-directory: ./${{ matrix.library }}
run: |
# This works because `node` is installed by default on GHA runners
CORES=$(node -e 'console.log(os.cpus().length)')
make transpile_rust TRANSPILE_TESTS_IN_RUST=1 CORES=$CORES

- name: Copy ${{ matrix.library }} Vector Files
if: ${{ matrix.library == 'TestVectors' }}
shell: bash
working-directory: ./${{ matrix.library }}
run: |
cp runtimes/java/*.json runtimes/rust/

- name: Test ${{ matrix.library }} Rust
shell: bash
working-directory: ./${{ matrix.library }}
run: |
make test_rust

- name: Test Examples for Rust in ${{ matrix.library }}
if: ${{ matrix.library == 'DynamoDbEncryption' }}
working-directory: ./${{ matrix.library }}/runtimes/rust/
shell: bash
run: |
cargo run --example main
5 changes: 5 additions & 0 deletions .github/workflows/manual.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ jobs:
with:
dafny: ${{ inputs.dafny }}
regenerate-code: ${{ inputs.regenerate-code }}
manual-ci-rust:
uses: ./.github/workflows/library_rust_tests.yml
with:
dafny: ${{ inputs.dafny }}
regenerate-code: ${{ inputs.regenerate-code }}
manual-ci-net-test-vectors:
uses: ./.github/workflows/ci_test_vector_net.yml
with:
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/mpl-head.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ jobs:
with:
dafny: ${{needs.getVersion.outputs.version}}
mpl-head: true
mpl-head-ci-rust:
needs: getVersion
uses: ./.github/workflows/library_rust_tests.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
mpl-head: true
mpl-head-ci-net-test-vectors:
needs: getVersion
uses: ./.github/workflows/ci_test_vector_net.yml
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ jobs:
with:
dafny: "nightly-latest"
regenerate-code: true
dafny-nightly-rust:
if: github.event_name != 'schedule' || github.repository_owner == 'aws'
uses: ./.github/workflows/library_rust_tests.yml
with:
dafny: "nightly-latest"
regenerate-code: true
dafny-nightly-test-vectors-net:
if: github.event_name != 'schedule' || github.repository_owner == 'aws'
uses: ./.github/workflows/ci_test_vector_net.yml
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ jobs:
uses: ./.github/workflows/ci_test_net.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
pr-ci-rust:
needs: getVersion
uses: ./.github/workflows/library_rust_tests.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
pr-ci-net-test-vectors:
needs: getVersion
uses: ./.github/workflows/ci_test_vector_net.yml
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ jobs:
uses: ./.github/workflows/ci_test_net.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
pr-ci-rust:
needs: getVersion
uses: ./.github/workflows/library_rust_tests.yml
with:
dafny: ${{needs.getVersion.outputs.version}}
pr-ci-net-test-vectors:
needs: getVersion
uses: ./.github/workflows/ci_test_vector_net.yml
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
submodules
target
1 change: 0 additions & 1 deletion DynamoDbEncryption/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ ImplementationFromDafny.cs
TestsFromDafny.cs
ImplementationFromDafny-cs.dtr
TestsFromDafny-cs.dtr
**/bin
**/obj
node_modules
project.properties
29 changes: 24 additions & 5 deletions DynamoDbEncryption/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

CORES=2

TRANSPILE_TESTS_IN_RUST=1

include ../SharedMakefile.mk

DIR_STRUCTURE_V2=V2
Expand All @@ -13,6 +15,28 @@ PROJECT_SERVICES := \
DynamoDbEncryptionTransforms \
StructuredEncryption

MAIN_SERVICE_FOR_RUST := DynamoDbEncryptionTransforms

RUST_OTHER_FILES := \
runtimes/rust/src/aes_gcm.rs \
runtimes/rust/src/aes_kdf_ctr.rs \
runtimes/rust/src/ddb.rs \
runtimes/rust/src/concurrent_call.rs \
runtimes/rust/src/dafny_libraries.rs \
runtimes/rust/src/digest.rs \
runtimes/rust/src/ecdh.rs \
runtimes/rust/src/ecdsa.rs \
runtimes/rust/src/hmac.rs \
runtimes/rust/src/kms.rs \
runtimes/rust/src/local_cmc.rs \
runtimes/rust/src/random.rs \
runtimes/rust/src/rsa.rs \
runtimes/rust/src/sets.rs \
runtimes/rust/src/software_externs.rs \
runtimes/rust/src/storm_tracker.rs \
runtimes/rust/src/time.rs \
runtimes/rust/src/uuid.rs

# Namespace for each local service
# Currently our build relies on local services and namespaces being 1:1
SERVICE_NAMESPACE_StructuredEncryption=aws.cryptography.dbEncryptionSdk.structuredEncryption
Expand Down Expand Up @@ -74,8 +98,3 @@ SERVICE_DEPS_DynamoDbEncryptionTransforms := \
DynamoDbEncryption/dafny/DynamoDbEncryption \
DynamoDbEncryption/dafny/StructuredEncryption \
DynamoDbEncryption/dafny/DynamoDbItemEncryptor

polymorph:
export DAFNY_VERSION=4.2
npm i --no-save prettier@3 [email protected]
make polymorph_code_gen PROJECT_DEPENDENCIES=
11 changes: 10 additions & 1 deletion DynamoDbEncryption/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ Within `runtimes/java`:
- `ImplementationFromDafny.cs` contains all Dafny to .NET transpiled code.
- `Generated/` contains all Smithy to .NET generated code.

#### Rust

`runtimes/rust` contains the Rust related code and build instructions for this project.

- `src/` contains all hand written Dotnet code, including externs, and also all Smithy to Rust generated code.
- `src/implementation_from_dafny.cs` contains all Dafny to .NET transpiled code.

### Development

Common Makefile targets are:
Expand Down Expand Up @@ -74,10 +81,12 @@ Common Makefile targets are:
that end up adding or removing dafny-generated files.
- The above command takes a while to complete.
- `make test_net_mac_intel` builds and tests the transpiled code in .NET in an Intel-MacOS environment.
- `make transpile_rust` transpiles all of the Dafny code into runtimes/rust/src/implementation_from_dafny.
- `make polymorph_rust` transpiles the smithy files into untimes/rust/src/\*.rs

### Development Requirements

- Dafny 4.1.0: https://github.com/dafny-lang/dafny
- Dafny 4.9.0: https://github.com/dafny-lang/dafny
- A Java 8 or newer development environment

#### (Optional) Dafny Report Generator Requirements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,16 @@ module {:extern "software.amazon.cryptography.dbencryptionsdk.dynamodb.internald
| CollectionOfErrors(list: seq<Error>, nameonly message: string)
// The Opaque error, used for native, extern, wrapped or unknown errors
| Opaque(obj: object)
type OpaqueError = e: Error | e.Opaque? witness *
// A better Opaque, with a visible string representation.
| OpaqueWithText(obj: object, objMessage : string)
type OpaqueError = e: Error | e.Opaque? || e.OpaqueWithText? witness *
// This dummy subset type is included to make sure Dafny
// always generates a _ExternBase___default.java class.
type DummySubsetType = x: int | IsDummySubsetType(x) witness 1
predicate method IsDummySubsetType(x: int) {
0 < x
}

}
abstract module AbstractAwsCryptographyDbEncryptionSdkDynamoDbService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ use aws.cryptography.materialProviders#AwsCryptographicMaterialProviders
AwsCryptographicPrimitives,
DynamoDB_20120810,
AwsCryptographicMaterialProviders,
StructuredEncryption
StructuredEncryption,
KeyStore
]
)
service DynamoDbEncryption {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,16 @@ module {:extern "software.amazon.cryptography.dbencryptionsdk.dynamodb.transform
| CollectionOfErrors(list: seq<Error>, nameonly message: string)
// The Opaque error, used for native, extern, wrapped or unknown errors
| Opaque(obj: object)
type OpaqueError = e: Error | e.Opaque? witness *
// A better Opaque, with a visible string representation.
| OpaqueWithText(obj: object, objMessage : string)
type OpaqueError = e: Error | e.Opaque? || e.OpaqueWithText? witness *
// This dummy subset type is included to make sure Dafny
// always generates a _ExternBase___default.java class.
type DummySubsetType = x: int | IsDummySubsetType(x) witness 1
predicate method IsDummySubsetType(x: int) {
0 < x
}

}
abstract module AbstractAwsCryptographyDbEncryptionSdkDynamoDbTransformsService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ use aws.polymorph#javadoc
DynamoDB_20120810,
DynamoDbEncryption,
DynamoDbItemEncryptor,
StructuredEncryption
StructuredEncryption,
AwsCryptographicMaterialProviders
]
)
service DynamoDbEncryptionTransforms {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module BatchWriteItemTransform {
modifies ModifiesConfig(config)
{
var tableNames := input.sdkInput.RequestItems.Keys;
var result : map<DDB.TableName, DDB.WriteRequests> := map[];
var result : map<DDB.TableArn, DDB.WriteRequests> := map[];
var tableNamesSeq := SortedSets.ComputeSetToSequence(tableNames);
ghost var tableNamesSet' := tableNames;
var i := 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,16 @@ module {:extern "software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencry
| CollectionOfErrors(list: seq<Error>, nameonly message: string)
// The Opaque error, used for native, extern, wrapped or unknown errors
| Opaque(obj: object)
type OpaqueError = e: Error | e.Opaque? witness *
// A better Opaque, with a visible string representation.
| OpaqueWithText(obj: object, objMessage : string)
type OpaqueError = e: Error | e.Opaque? || e.OpaqueWithText? witness *
// This dummy subset type is included to make sure Dafny
// always generates a _ExternBase___default.java class.
type DummySubsetType = x: int | IsDummySubsetType(x) witness 1
predicate method IsDummySubsetType(x: int) {
0 < x
}

}
abstract module AbstractAwsCryptographyDbEncryptionSdkDynamoDbItemEncryptorService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,16 @@ module {:extern "software.amazon.cryptography.dbencryptionsdk.structuredencrypti
| CollectionOfErrors(list: seq<Error>, nameonly message: string)
// The Opaque error, used for native, extern, wrapped or unknown errors
| Opaque(obj: object)
type OpaqueError = e: Error | e.Opaque? witness *
// A better Opaque, with a visible string representation.
| OpaqueWithText(obj: object, objMessage : string)
type OpaqueError = e: Error | e.Opaque? || e.OpaqueWithText? witness *
// This dummy subset type is included to make sure Dafny
// always generates a _ExternBase___default.java class.
type DummySubsetType = x: int | IsDummySubsetType(x) witness 1
predicate method IsDummySubsetType(x: int) {
0 < x
}

}
abstract module AbstractAwsCryptographyDbEncryptionSdkStructuredEncryptionService
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,10 @@ module {:options "/functionSyntax:4" } Canonize {
assert forall k <- output :: exists x :: x in origData && Updated3(x, k, DoDecrypt) by {
Update2ImpliesUpdate3();
assert forall val <- input :: exists x :: x in origData && Updated2(x, val, DoDecrypt);
assert forall i | 0 <= i < |input| :: exists x :: x in origData && Updated2(x, input[i], DoDecrypt) by {
InputIsInput(origData, input);
}
assume {:axiom} forall i | 0 <= i < |input| :: exists x :: x in origData && Updated2(x, input[i], DoDecrypt);
// assert forall i | 0 <= i < |input| :: exists x :: x in origData && Updated2(x, input[i], DoDecrypt) by {
// InputIsInput(origData, input);
// }
assert forall newVal <- output :: exists x :: x in origData && Updated3(x, newVal, DoDecrypt);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.internaldafny.types;

public class __default
extends software.amazon.cryptography.dbencryptionsdk.dynamodb.itemencryptor.internaldafny.types._ExternBase___default {}
Loading
Loading