Skip to content

Commit e9b905f

Browse files
use env variable for the path of the typescript project test vectors
+ in addtion to some refactorying + update README file
1 parent be53022 commit e9b905f

File tree

4 files changed

+352
-259
lines changed

4 files changed

+352
-259
lines changed

nucypher-core/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ Bindings for several languages are available:
1717
* [JavaScript](https://github.com/nucypher/nucypher-core/tree/main/nucypher-core-wasm) (WASM-based)
1818
* [Python](https://github.com/nucypher/nucypher-core/tree/main/nucypher-core-python)
1919

20+
## Cross-Implementation Testing
21+
22+
This library tests generate test vectors for ensuring compatibility between different implementations. The test vector generators automatically produce JSON files in both the Rust project and the TypeScript project.
23+
24+
### Setting Custom Path for TypeScript Test Vectors
25+
26+
By default, the test vector generators will look for the TypeScript project at a relative path. If your project structure is different, you can customize the TypeScript project path using an environment variable:
27+
28+
```bash
29+
# Generate shared secret test vectors with custom TypeScript project path
30+
TS_PROJECT_TEST_VECTORS_PATH=/path/to/taco-web/packages/shared/test/fixtures/ cargo test -p nucypher-core --test generate_shared_secret_vectors
31+
```
32+
2033
[crate-image]: https://img.shields.io/crates/v/nucypher-core.svg
2134
[crate-link]: https://crates.io/crates/nucypher-core
2235
[docs-image]: https://docs.rs/nucypher-core/badge.svg
Lines changed: 154 additions & 154 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,8 @@
11
{
2-
"testVectors": [
2+
"test_vectors": [
33
{
4-
"description": "Basic encryption/decryption compatibility",
5-
"expected_ciphertext": "0102030405060708090a0b0c30e02d19293bd79329c9232eacc4e82eca99e0ea66e4da3808bccbacb3fd2ccbce94fe0c26cbbb81be779817",
6-
"fixed_nonce": [
7-
1,
8-
2,
9-
3,
10-
4,
11-
5,
12-
6,
13-
7,
14-
8,
15-
9,
16-
10,
17-
11,
18-
12
19-
],
204
"id": "vector1",
21-
"plaintext": "This is a fixed test message",
5+
"description": "Fixed nonce encryption with known plaintext",
226
"shared_secret": [
237
0,
248
1,
@@ -52,150 +36,81 @@
5236
29,
5337
30,
5438
31
55-
]
56-
},
57-
{
58-
"description": "Empty plaintext compatibility",
59-
"expected_ciphertext": "102030405060708090a0b0c0d9abc79645718dc328d5c3faa129fced",
39+
],
40+
"plaintext": "This is a test message",
6041
"fixed_nonce": [
61-
16,
62-
32,
63-
48,
64-
64,
65-
80,
66-
96,
67-
112,
68-
128,
69-
144,
70-
160,
71-
176,
72-
192
42+
0,
43+
0,
44+
0,
45+
0,
46+
0,
47+
0,
48+
0,
49+
0,
50+
0,
51+
0,
52+
0,
53+
0
7354
],
74-
"id": "vector2",
75-
"plaintext": "",
76-
"shared_secret": [
77-
32,
78-
33,
79-
34,
80-
35,
81-
36,
82-
37,
83-
38,
84-
39,
85-
40,
86-
41,
87-
42,
88-
43,
89-
44,
90-
45,
91-
46,
92-
47,
93-
48,
94-
49,
95-
50,
96-
51,
97-
52,
98-
53,
99-
54,
100-
55,
101-
56,
102-
57,
103-
58,
104-
59,
105-
60,
106-
61,
107-
62,
108-
63
109-
]
55+
"expected_ciphertext": "0000000000000000000000004cd02b428d8fd5f172412804dc376e4a9dc2809486c8b548d407dad8f75ee84d6d9e92a42c4a"
11056
},
11157
{
112-
"description": "Rust-generated ciphertext for TypeScript compatibility check",
113-
"expected_plaintext": "This is a message encrypted by the Rust implementation",
114-
"id": "vector3",
115-
"rust_generated_ciphertext": [
116-
244,
117-
240,
118-
54,
58+
"id": "vector2",
59+
"description": "Fixed nonce encryption with alternative values",
60+
"shared_secret": [
61+
31,
62+
30,
63+
29,
64+
28,
65+
27,
66+
26,
67+
25,
11968
24,
120-
5,
121-
65,
122-
204,
123-
10,
124-
149,
69+
23,
70+
22,
71+
21,
72+
20,
73+
19,
74+
18,
75+
17,
76+
16,
77+
15,
78+
14,
79+
13,
80+
12,
81+
11,
12582
10,
126-
78,
127-
107,
128-
203,
129-
196,
130-
102,
131-
251,
132-
108,
133-
158,
134-
36,
83+
9,
84+
8,
13585
7,
136-
14,
137-
87,
138-
153,
139-
251,
140-
176,
141-
242,
142-
94,
143-
153,
144-
244,
145-
118,
146-
124,
147-
216,
148-
154,
86+
6,
14987
5,
150-
88,
151-
98,
152-
171,
153-
221,
154-
222,
155-
14,
156-
247,
157-
21,
158-
74,
159-
25,
160-
205,
161-
80,
162-
35,
163-
47,
164-
195,
165-
218,
166-
221,
167-
23,
168-
85,
169-
23,
170-
82,
171-
145,
172-
234,
173-
171,
174-
136,
175-
141,
176-
215,
177-
95,
178-
178,
179-
103,
180-
141,
181-
70,
182-
236,
183-
104,
184-
80,
185-
106,
186-
249,
187-
218,
188-
236,
189-
96,
190-
76,
191-
77,
192-
239,
193-
197,
194-
216,
195-
31,
196-
187,
197-
146
88+
4,
89+
3,
90+
2,
91+
1,
92+
0
19893
],
94+
"plaintext": "Another test message with different content",
95+
"fixed_nonce": [
96+
1,
97+
1,
98+
1,
99+
1,
100+
1,
101+
1,
102+
1,
103+
1,
104+
1,
105+
1,
106+
1,
107+
1
108+
],
109+
"expected_ciphertext": "010101010101010101010101a9ac42148ddc2b18ec66eb228f8393ed84270eccf9d30188b990190773713e3ca4cdf8f13b94d03e1298cc9b6d851c4d7f18cafc64668515639e37"
110+
},
111+
{
112+
"id": "vector3",
113+
"description": "Rust-generated ciphertext for TypeScript compatibility check",
199114
"shared_secret": [
200115
0,
201116
1,
@@ -229,7 +144,92 @@
229144
29,
230145
30,
231146
31
232-
]
147+
],
148+
"rust_generated_ciphertext": [
149+
118,
150+
106,
151+
153,
152+
16,
153+
1,
154+
115,
155+
18,
156+
253,
157+
100,
158+
80,
159+
9,
160+
0,
161+
55,
162+
156,
163+
166,
164+
142,
165+
220,
166+
253,
167+
109,
168+
125,
169+
97,
170+
126,
171+
192,
172+
101,
173+
42,
174+
48,
175+
110,
176+
248,
177+
175,
178+
43,
179+
181,
180+
217,
181+
124,
182+
18,
183+
126,
184+
121,
185+
19,
186+
43,
187+
46,
188+
19,
189+
11,
190+
70,
191+
250,
192+
216,
193+
252,
194+
125,
195+
192,
196+
154,
197+
40,
198+
123,
199+
18,
200+
222,
201+
64,
202+
112,
203+
199,
204+
90,
205+
66,
206+
116,
207+
81,
208+
189,
209+
234,
210+
221,
211+
255,
212+
245,
213+
48,
214+
240,
215+
85,
216+
212,
217+
153,
218+
7,
219+
11,
220+
92,
221+
31,
222+
228,
223+
76,
224+
66,
225+
141,
226+
7,
227+
3,
228+
27,
229+
91,
230+
21
231+
],
232+
"expected_plaintext": "This is a message encrypted by the Rust implementation"
233233
}
234234
]
235235
}

0 commit comments

Comments
 (0)