Skip to content

Commit 01022a8

Browse files
authored
chore(docs): Update docs for Rust; add TRANSPILE_TESTS_IN_RUST to Makefiles (#702)
1 parent 792fd2a commit 01022a8

File tree

8 files changed

+180
-8
lines changed

8 files changed

+180
-8
lines changed

.github/workflows/library_interop_test_vectors.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ jobs:
141141
working-directory: ./${{ matrix.library }}
142142
run: |
143143
CORES=$(node -e 'console.log(os.cpus().length)')
144-
make transpile_rust TRANSPILE_TESTS_IN_RUST=1 CORES=$CORES
144+
make transpile_rust CORES=$CORES
145145
146146
- name: Setup gradle
147147
if: matrix.language == 'java'
@@ -294,7 +294,7 @@ jobs:
294294
working-directory: ./${{ matrix.library }}
295295
run: |
296296
CORES=$(node -e 'console.log(os.cpus().length)')
297-
make transpile_rust TRANSPILE_TESTS_IN_RUST=1 CORES=$CORES
297+
make transpile_rust CORES=$CORES
298298
299299
- name: Download Encrypt Manifest Artifact
300300
uses: actions/download-artifact@v4

.github/workflows/library_rust_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
run: |
106106
# This works because `node` is installed by default on GHA runners
107107
CORES=$(node -e 'console.log(os.cpus().length)')
108-
make transpile_rust TRANSPILE_TESTS_IN_RUST=1 CORES=$CORES
108+
make transpile_rust CORES=$CORES
109109
110110
# Remove Rust hacks once Dafny fixes this
111111
- name: Update implementation_from_dafny.rs to add deps

AwsEncryptionSDK/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# SPDX-License-Identifier: Apache-2.0
33
CORES=2
44

5+
TRANSPILE_TESTS_IN_RUST := 1
6+
57
include ../SharedMakefileV2.mk
68

79
DIR_STRUCTURE_V2=V2
Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,62 @@
1-
# This is NOT ready for production
1+
# AWS Encryption SDK for Rust
22

3-
# Use at your own risk
3+
AWS Encryption SDK for Rust
4+
5+
## Using the AWS Encryption SDK for Rust
6+
7+
The AWS Encryption SDK is available on [Crates.io](https://www.crates.io/).
8+
9+
## Building the AWS Encryption SDK for Rust
10+
11+
To build, the AWS Encryption SDK requires the most up to date version of [Dafny](https://github.com/dafny-lang/dafny) on your PATH.
12+
13+
You will also need to ensure that you fetch all submodules using either `git clone --recursive ...` when cloning the repository or `git submodule update --init` on an existing clone.
14+
15+
To setup your project to use the AWS Encryption SDK in Rust, run:
16+
17+
```
18+
cd AwsEncryptionSDK
19+
# Polymorph smithy to Rust
20+
make polymorph_rust
21+
# Transpile Dafny to Rust
22+
make transpile_rust
23+
```
24+
25+
### (Optional) Set up the AWS Encryption SDK to work with AWS KMS
26+
27+
If you set up the AWS Encryption SDK to use the AWS KMS Keyring,
28+
the AWS Encryption SDK will make calls to AWS KMS on your behalf,
29+
using the appropriate AWS SDK.
30+
31+
However, you must first set up AWS credentials for use with the AWS SDK.
32+
33+
## Testing the AWS Encryption SDK for Rust
34+
35+
### Configure AWS credentials
36+
37+
To run the test suite you must first set up AWS credentials for use with the AWS SDK.
38+
This is required in order to run the integration tests, which use a KMS Keyring against a publicly accessible KMS CMK.
39+
40+
### Run the tests
41+
42+
Run the test suite with:
43+
44+
```
45+
cd AwsEncryptionSDK
46+
make test_rust
47+
```
48+
49+
Run tests on examples, to ensure they are up to date:
50+
51+
```
52+
cd AwsEncryptionSDK/runtimes/rust/
53+
cargo test --examples
54+
```
55+
56+
Please look at the Examples on how to use the Encryption SDK in Rust [here](examples).
57+
58+
Please note that tests and test vectors require internet access and valid AWS credentials, since calls to KMS are made as part of the test workflow.
59+
60+
## License
61+
62+
This library is licensed under the Apache 2.0 License.
Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,90 @@
1-
# TODO: Update for Rust
1+
# AWS Encryption SDK for Rust Examples
2+
3+
This section features examples that show you
4+
how to use the AWS Encryption SDK.
5+
We demonstrate how to use the encryption and decryption APIs
6+
and how to set up some common configuration patterns.
7+
8+
## APIs
9+
10+
The AWS Encryption SDK provides two high-level APIs:
11+
one-step APIs that process the entire operation in memory
12+
and streaming APIs.
13+
14+
You can find examples that demonstrate these APIs
15+
in the [`examples/`](./) directory.
16+
17+
* [How to encrypt and decrypt](./keyring/aws_kms_keyring_example.rs)
18+
* [How to change the algorithm suite](./set_encryption_algorithm_suite_example.rs)
19+
* [How to set the commitment policy](./set_commitment_policy_example.rs)
20+
* [How to limit the number of encrypted data keys (EDKs)](./limit_encrypted_data_keys_example.rs)
21+
22+
## Configuration
23+
24+
To use the encryption and decryption APIs,
25+
you need to describe how you want the library to protect your data keys.
26+
You can do this by configuring
27+
[keyrings](#keyrings) or [cryptographic materials managers](#cryptographic-materials-managers).
28+
These examples will show you how to use the configuration tools that we include for you
29+
and how to create some of your own.
30+
We start with AWS KMS examples, then show how to use other wrapping keys.
31+
32+
* Using AWS Key Management Service (AWS KMS)
33+
* [How to use one AWS KMS key](./keyring/aws_kms_keyring_example.rs)
34+
* [How to use multiple AWS KMS keys in different regions](./keyring/aws_kms_mrk_discovery_multi_keyring_example.rs)
35+
* [How to decrypt when you don't know the AWS KMS key](./keyring/aws_kms_discovery_keyring_example.rs)
36+
* [How to limit decryption to a single region](./keyring/aws_kms_mrk_discovery_keyring_example.rs)
37+
* [How to decrypt with a preferred region but failover to others](./keyring/aws_kms_mrk_discovery_multi_keyring_example.rs)
38+
* [How to reproduce the behavior of an AWS KMS master key provider](./keyring/aws_kms_multi_keyring_example.rs)
39+
* Using raw wrapping keys
40+
* [How to use a raw AES wrapping key](./keyring/raw_aes_keyring_example.rs)
41+
* [How to use a raw RSA wrapping key](./keyring/raw_rsa_keyring_example.rs)
42+
* Combining wrapping keys
43+
* [How to combine AWS KMS with an offline escrow key](./keyring/multi_keyring_example.rs)
44+
* How to restrict algorithm suites
45+
* [with a custom cryptographic materials manager](./cryptographic_materials_manager/restrict_algorithm_suite/signing_suite_only_cmm.rs)
46+
47+
### Keyrings
48+
49+
Keyrings are the most common way for you to configure the AWS Encryption SDK.
50+
They determine how the AWS Encryption SDK protects your data.
51+
You can find these examples in [`examples/keyring`](./keyring).
52+
53+
### Cryptographic Materials Managers
54+
55+
Keyrings define how your data keys are protected,
56+
but there is more going on here than just protecting data keys.
57+
58+
Cryptographic materials managers give you higher-level controls
59+
over how the AWS Encryption SDK protects your data.
60+
This can include things like
61+
enforcing the use of certain algorithm suites or encryption context settings,
62+
reusing data keys across messages,
63+
or changing how you interact with keyrings.
64+
You can find these examples in
65+
[`examples/cryptographic_materials_manager`](./cryptographic_materials_manager).
66+
67+
### Client Supplier
68+
69+
The AWS Encryption SDK creates AWS KMS clients when interacting with AWS KMS.
70+
In case the default AWS KMS client configuration doesn't suit your needs,
71+
you can configure clients by defining a custom Client Supplier.
72+
For example, your Client Supplier could tune
73+
the retry and timeout settings on the client, or use different credentials
74+
based on which region is being called. In our
75+
[regional_role_client_supplier](./client_supplier/regional_role_client_supplier.rs)
76+
example, we show how you can build a custom Client Supplier which
77+
creates clients by assuming different IAM roles for different regions.
78+
79+
# Writing Examples
80+
81+
If you want to contribute a new example, that's awesome!
82+
To make sure that your example is tested in our CI,
83+
please make sure that it meets the following requirements:
84+
85+
1. The example MUST be a distinct subdirectory or file in the [`examples/`](./) directory.
86+
1. The example MAY be nested arbitrarily deeply. However, each example file MUST be added to the `mod.rs` files appropriately according to the directory structure. If the example is in the root directory [`examples/`](./), you MUST also add the module to the [`main.rs`](./main.rs) file. For instance, `pub mod set_commitment_policy_example;`.
87+
1. Each example file MUST contain exactly one example.
88+
1. Each example filename MUST be descriptive.
89+
1. Each example file MUST contain a testing function with the attribute `#[tokio::test(flavor = "multi_thread")]` just like the one at the end of the [KMS Keyring](./keyring/aws_kms_keyring_example.rs).
90+
1. Each example MUST also be called inside the `main` function of [main.rs](./main.rs).

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ dotnet build -t:VerifyDafny test
2222
The tests currently require native implementations of cryptographic primitives and other methods,
2323
so they can only be run when embedding this library into one of the compilation target languages supported by Dafny:
2424

25-
- [.NET](aws-encryption-sdk-net)
25+
- [.NET](./AwsEncryptionSDK/runtimes/net/)
26+
- [Rust](./AwsEncryptionSDK/runtimes/rust/)
2627

2728
## Generating Code from Smithy Model
2829

@@ -39,12 +40,20 @@ To run the code generator, open any of the modules (e.g. AwsCryptographyPrimitiv
3940
The AWS Encryption SDK for Dafny must be transpiled to a runtime to be used.
4041
There is no Dafny runtime, so there is no concept of "running the AWS Encryption SDK for Dafny".
4142

42-
To transpile the generated code to a runtime (e.g. Dotnet), open the module, then run:
43+
To transpile the generated code to a runtime, open the module `AwsEncryptionSDK`, then run:
44+
45+
#### For .NET
4346

4447
```
4548
make transpile_net
4649
```
4750

51+
#### For Rust
52+
53+
```
54+
make transpile_rust
55+
```
56+
4857
## Generate Duvet Reports
4958

5059
This repo uses Duvet to directly document the [specification](https://github.com/awslabs/aws-encryption-sdk-specification) alongside this implementation.

TestVectors/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
CORES=2
55

6+
TRANSPILE_TESTS_IN_RUST=1
7+
68
include ../SharedMakefileV2.mk
79

810
DIR_STRUCTURE_V2=V2

TestVectors/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,22 @@ of the Encryption SDK and runtimes.
1616

1717
### Building and Running
1818

19+
#### For .NET
20+
1921
1. Start in the root `./TestVectors` directory
2022
2. Run `make transpile_net`
2123
3. Run `make test_net_mac_intel` if running on a MacOS environment or
2224
`make test_net` if running on a Windows or Linux environment.
2325

26+
#### For Rust
27+
28+
1. Start in the root `./TestVectors` directory
29+
2. Run `make polymorph_rust`
30+
3. Run `make transpile_rust`
31+
5. Run `make test_rust`
32+
33+
Note: If you run into a stack overflow error while running `make test_rust`, run `export RUST_MIN_STACK=104857600`, and re-run `make test_rust`.
34+
2435
## Security
2536

2637
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.

0 commit comments

Comments
 (0)