Skip to content

Commit 2d637f1

Browse files
committed
Add test vectors for ZIP 32 registered keys.
Signed-off-by: Daira-Emma Hopwood <[email protected]>
1 parent 9dc587d commit 2d637f1

File tree

9 files changed

+205
-67
lines changed

9 files changed

+205
-67
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ f4jumble_long = "zcash_test_vectors.f4jumble:long_test_vectors"
4141
unified_address = "zcash_test_vectors.unified_address:main"
4242
unified_full_viewing_keys = "zcash_test_vectors.unified_full_viewing_keys:main"
4343
unified_incoming_viewing_keys = "zcash_test_vectors.unified_incoming_viewing_keys:main"
44+
zip_0032_registered = "zcash_test_vectors.zip_0032:registered_key_derivation_tvs"
4445
zip_0032_arbitrary = "zcash_test_vectors.zip_0032:arbitrary_key_derivation_tvs"
4546
zip_0143 = "zcash_test_vectors.zip_0143:main"
4647
zip_0243 = "zcash_test_vectors.zip_0243:main"

regenerate.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ case "$2" in
4545
unified_address
4646
unified_full_viewing_keys
4747
unified_incoming_viewing_keys
48+
zip_0032_registered
4849
zip_0032_arbitrary
4950
zip_0143
5051
zip_0243
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
["From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0032_registered.py"],
3+
["context_string, seed, zip_number, path, sk, c, full_width"],
4+
["5a63617368207465737420766563746f7273", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 1, [], "53a71507e6dfda588bc1e138c2657c9269e55f5d9b99e3887c134008193a2f47", "08bb26aae21d4efdc3249b9557fcd9131e8b9827241d9f61d0d774bb4fed3de6", null],
5+
["5a63617368207465737420766563746f7273", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 1, [[2147483650, "7472616e7320726967687473206172652068756d616e20726967687473"]], "02dc25cc40310eed08b028e07fae9adbee2fbe56a4694def0401e656dfae0211", "d8f9d8a1f81d1b5d5506b5ff942d2ff3dae7a63f57d6b8c7fbe58149823cc6ec", "255d75b5f97dd880a14460ab0a28938e7ba497ceb1457fff2992e9015a8403f8c08112b7a94cf539c21c9da7ee99897be9476b6813532ee22c8947d753b72bdf"],
6+
["5a63617368207465737420766563746f7273", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 1, [[2147483650, "7472616e7320726967687473206172652068756d616e20726967687473"], [2147483651, ""]], "a127db66628b256e5b664d54050c1e6b028963aea22b04d1bc6f48123674ed82", "340084033605edca11463ffec56bf0cac425c410e953628671cec6a6514c32a8", "7f853eef001b1bc5a1a5e67f5dfd0e90427596d4842f5b10a111e97c4073203cedf6b80a85145e5061acd29bc5a4e349b14f8557a7033e23b066b7ce2409d973"]
7+
]

test-vectors/rust/zip_0032_arbitrary.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
struct TestVector {
2-
context_string: Vec<u8>,
2+
context_string: &'static [u8],
33
seed: [u8; 32],
4-
ikm: Option<Vec<u8>>,
5-
path: Vec<u32>,
4+
ikm: Option<&'static [u8]>,
5+
path: &'static [u32],
66
sk: [u8; 32],
77
c: [u8; 32],
88
}
99

1010
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0032_arbitrary.py
1111
const TEST_VECTORS: &[TestVector] = &[
1212
TestVector {
13-
context_string: vec![
13+
context_string: &[
1414
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
1515
],
1616
seed: [
1717
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
1818
],
19-
ikm: Some(vec![
19+
ikm: Some(&[
2020
0x12, 0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73, 0x20, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
2121
]),
22-
path: vec![
22+
path: &[
2323
],
2424
sk: [
2525
0xe9, 0xda, 0x88, 0x06, 0x40, 0x9d, 0xc3, 0xc3, 0xeb, 0xd1, 0xfc, 0x2a, 0x71, 0xc8, 0x79, 0xc1, 0x3d, 0xd7, 0xaa, 0x93, 0xed, 0xe8, 0x03, 0xbf, 0x1a, 0x83, 0x41, 0x4b, 0x9d, 0x3b, 0x15, 0x8a
@@ -29,14 +29,14 @@
2929
],
3030
},
3131
TestVector {
32-
context_string: vec![
32+
context_string: &[
3333
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
3434
],
3535
seed: [
3636
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
3737
],
3838
ikm: None,
39-
path: vec![
39+
path: &[
4040
2147483649,
4141
],
4242
sk: [
@@ -47,14 +47,14 @@
4747
],
4848
},
4949
TestVector {
50-
context_string: vec![
50+
context_string: &[
5151
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
5252
],
5353
seed: [
5454
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
5555
],
5656
ikm: None,
57-
path: vec![
57+
path: &[
5858
2147483649,
5959
2147483650,
6060
],
@@ -66,14 +66,14 @@
6666
],
6767
},
6868
TestVector {
69-
context_string: vec![
69+
context_string: &[
7070
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
7171
],
7272
seed: [
7373
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
7474
],
7575
ikm: None,
76-
path: vec![
76+
path: &[
7777
2147483649,
7878
2147483650,
7979
2147483651,
@@ -86,14 +86,14 @@
8686
],
8787
},
8888
TestVector {
89-
context_string: vec![
89+
context_string: &[
9090
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
9191
],
9292
seed: [
9393
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
9494
],
9595
ikm: None,
96-
path: vec![
96+
path: &[
9797
2147483680,
9898
],
9999
sk: [
@@ -104,14 +104,14 @@
104104
],
105105
},
106106
TestVector {
107-
context_string: vec![
107+
context_string: &[
108108
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
109109
],
110110
seed: [
111111
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
112112
],
113113
ikm: None,
114-
path: vec![
114+
path: &[
115115
2147483680,
116116
2147483781,
117117
],
@@ -123,14 +123,14 @@
123123
],
124124
},
125125
TestVector {
126-
context_string: vec![
126+
context_string: &[
127127
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
128128
],
129129
seed: [
130130
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
131131
],
132132
ikm: None,
133-
path: vec![
133+
path: &[
134134
2147483680,
135135
2147483781,
136136
2147483648,
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
struct TestVector {
2+
context_string: &'static [u8],
3+
seed: [u8; 32],
4+
zip_number: u16,
5+
path: &'static [(u32, &'static [u8])],
6+
sk: [u8; 32],
7+
c: [u8; 32],
8+
full_width: Option<[u8; 64]>,
9+
}
10+
11+
// From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0032_registered.py
12+
const TEST_VECTORS: &[TestVector] = &[
13+
TestVector {
14+
context_string: &[
15+
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
16+
],
17+
seed: [
18+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
19+
],
20+
zip_number: 1,
21+
path: &[
22+
],
23+
sk: [
24+
0x53, 0xa7, 0x15, 0x07, 0xe6, 0xdf, 0xda, 0x58, 0x8b, 0xc1, 0xe1, 0x38, 0xc2, 0x65, 0x7c, 0x92, 0x69, 0xe5, 0x5f, 0x5d, 0x9b, 0x99, 0xe3, 0x88, 0x7c, 0x13, 0x40, 0x08, 0x19, 0x3a, 0x2f, 0x47
25+
],
26+
c: [
27+
0x08, 0xbb, 0x26, 0xaa, 0xe2, 0x1d, 0x4e, 0xfd, 0xc3, 0x24, 0x9b, 0x95, 0x57, 0xfc, 0xd9, 0x13, 0x1e, 0x8b, 0x98, 0x27, 0x24, 0x1d, 0x9f, 0x61, 0xd0, 0xd7, 0x74, 0xbb, 0x4f, 0xed, 0x3d, 0xe6
28+
],
29+
full_width: None,
30+
},
31+
TestVector {
32+
context_string: &[
33+
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
34+
],
35+
seed: [
36+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
37+
],
38+
zip_number: 1,
39+
path: &[
40+
(2147483650, &[0x74, 0x72, 0x61, 0x6e, 0x73, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73]),
41+
],
42+
sk: [
43+
0x02, 0xdc, 0x25, 0xcc, 0x40, 0x31, 0x0e, 0xed, 0x08, 0xb0, 0x28, 0xe0, 0x7f, 0xae, 0x9a, 0xdb, 0xee, 0x2f, 0xbe, 0x56, 0xa4, 0x69, 0x4d, 0xef, 0x04, 0x01, 0xe6, 0x56, 0xdf, 0xae, 0x02, 0x11
44+
],
45+
c: [
46+
0xd8, 0xf9, 0xd8, 0xa1, 0xf8, 0x1d, 0x1b, 0x5d, 0x55, 0x06, 0xb5, 0xff, 0x94, 0x2d, 0x2f, 0xf3, 0xda, 0xe7, 0xa6, 0x3f, 0x57, 0xd6, 0xb8, 0xc7, 0xfb, 0xe5, 0x81, 0x49, 0x82, 0x3c, 0xc6, 0xec
47+
],
48+
full_width: Some([
49+
0x25, 0x5d, 0x75, 0xb5, 0xf9, 0x7d, 0xd8, 0x80, 0xa1, 0x44, 0x60, 0xab, 0x0a, 0x28, 0x93, 0x8e, 0x7b, 0xa4, 0x97, 0xce, 0xb1, 0x45, 0x7f, 0xff, 0x29, 0x92, 0xe9, 0x01, 0x5a, 0x84, 0x03, 0xf8, 0xc0, 0x81, 0x12, 0xb7, 0xa9, 0x4c, 0xf5, 0x39, 0xc2, 0x1c, 0x9d, 0xa7, 0xee, 0x99, 0x89, 0x7b, 0xe9, 0x47, 0x6b, 0x68, 0x13, 0x53, 0x2e, 0xe2, 0x2c, 0x89, 0x47, 0xd7, 0x53, 0xb7, 0x2b, 0xdf
50+
]),
51+
},
52+
TestVector {
53+
context_string: &[
54+
0x5a, 0x63, 0x61, 0x73, 0x68, 0x20, 0x74, 0x65, 0x73, 0x74, 0x20, 0x76, 0x65, 0x63, 0x74, 0x6f, 0x72, 0x73
55+
],
56+
seed: [
57+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
58+
],
59+
zip_number: 1,
60+
path: &[
61+
(2147483650, &[0x74, 0x72, 0x61, 0x6e, 0x73, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73, 0x20, 0x61, 0x72, 0x65, 0x20, 0x68, 0x75, 0x6d, 0x61, 0x6e, 0x20, 0x72, 0x69, 0x67, 0x68, 0x74, 0x73]),
62+
(2147483651, &[]),
63+
],
64+
sk: [
65+
0xa1, 0x27, 0xdb, 0x66, 0x62, 0x8b, 0x25, 0x6e, 0x5b, 0x66, 0x4d, 0x54, 0x05, 0x0c, 0x1e, 0x6b, 0x02, 0x89, 0x63, 0xae, 0xa2, 0x2b, 0x04, 0xd1, 0xbc, 0x6f, 0x48, 0x12, 0x36, 0x74, 0xed, 0x82
66+
],
67+
c: [
68+
0x34, 0x00, 0x84, 0x03, 0x36, 0x05, 0xed, 0xca, 0x11, 0x46, 0x3f, 0xfe, 0xc5, 0x6b, 0xf0, 0xca, 0xc4, 0x25, 0xc4, 0x10, 0xe9, 0x53, 0x62, 0x86, 0x71, 0xce, 0xc6, 0xa6, 0x51, 0x4c, 0x32, 0xa8
69+
],
70+
full_width: Some([
71+
0x7f, 0x85, 0x3e, 0xef, 0x00, 0x1b, 0x1b, 0xc5, 0xa1, 0xa5, 0xe6, 0x7f, 0x5d, 0xfd, 0x0e, 0x90, 0x42, 0x75, 0x96, 0xd4, 0x84, 0x2f, 0x5b, 0x10, 0xa1, 0x11, 0xe9, 0x7c, 0x40, 0x73, 0x20, 0x3c, 0xed, 0xf6, 0xb8, 0x0a, 0x85, 0x14, 0x5e, 0x50, 0x61, 0xac, 0xd2, 0x9b, 0xc5, 0xa4, 0xe3, 0x49, 0xb1, 0x4f, 0x85, 0x57, 0xa7, 0x03, 0x3e, 0x23, 0xb0, 0x66, 0xb7, 0xce, 0x24, 0x09, 0xd9, 0x73
72+
]),
73+
},
74+
];
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[
2+
["From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/zip_0032_registered.py"],
3+
["context_string, seed, zip_number, path, sk, c, full_width"],
4+
["5a63617368207465737420766563746f7273", "1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100", 1, [], "472f3a190840137c88e3999b5d5fe569927c65c238e1c18b58dadfe60715a753", "e63ded4fbb74d7d0619f1d2427988b1e13d9fc57959b24c3fd4e1de2aa26bb08", null],
5+
["5a63617368207465737420766563746f7273", "1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100", 1, [[2147483650, "7472616e7320726967687473206172652068756d616e20726967687473"]], "1102aedf56e60104ef4d69a456be2feedb9aae7fe028b008ed0e3140cc25dc02", "ecc63c824981e5fbc7b8d6573fa6e7daf32f2d94ffb506555d1b1df8a1d8f9d8", "255d75b5f97dd880a14460ab0a28938e7ba497ceb1457fff2992e9015a8403f8c08112b7a94cf539c21c9da7ee99897be9476b6813532ee22c8947d753b72bdf"],
6+
["5a63617368207465737420766563746f7273", "1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100", 1, [[2147483650, "7472616e7320726967687473206172652068756d616e20726967687473"], [2147483651, ""]], "82ed743612486fbcd1042ba2ae6389026b1e0c05544d665b6e258b6266db27a1", "a8324c51a6c6ce71866253e910c425c4caf06bc5fe3f4611caed053603840034", "7f853eef001b1bc5a1a5e67f5dfd0e90427596d4842f5b10a111e97c4073203cedf6b80a85145e5061acd29bc5a4e349b14f8557a7033e23b066b7ce2409d973"]
7+
]

zcash_test_vectors/orchard/key_components.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def master(cls, S):
6666
return cls(chaincode, sk)
6767

6868
def child(self, i):
69-
(sk_i, c_i) = CKDh(self.Orchard, self.data, self.chaincode, i)
69+
(sk_i, c_i) = CKDh(self.Orchard, self.data, self.chaincode, i, b"", False)
7070
return self.__class__(c_i, sk_i)
7171

7272

zcash_test_vectors/output.py

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def tv_value_json(value, bitcoin_flavoured):
2828
value = value.thing
2929

3030
def bitcoinify(value):
31+
if type(value) == tuple:
32+
return tuple((bitcoinify(v) for v in value))
33+
3134
if type(value) == list:
3235
return [bitcoinify(v) for v in value]
3336

@@ -62,23 +65,13 @@ def tv_json(filename, parts, vectors, bitcoin_flavoured):
6265
# Rust
6366
#
6467

65-
def tv_bytes_rust(name, value, pad):
66-
print('''%s%s: [
67-
%s%s
68-
%s],''' % (
69-
pad,
70-
name,
71-
pad,
72-
chunk(hexlify(value)),
73-
pad,
74-
))
75-
76-
def tv_vec_bytes_rust(name, value, pad):
77-
print('''%s%s: vec![
68+
def tv_bytes_rust(name, value, pad, kind=""):
69+
print('''%s%s: %s[
7870
%s%s
7971
%s],''' % (
8072
pad,
8173
name,
74+
kind,
8275
pad,
8376
chunk(hexlify(value)),
8477
pad,
@@ -95,34 +88,28 @@ def tv_vec_bool_rust(name, value, pad):
9588
pad,
9689
))
9790

91+
def tv_tuple_int_bytes_rust(name, value, pad):
92+
print("%s%s: &[" % (pad, name))
93+
for (i, t) in value:
94+
print("%s (%d, &[%s])," % (pad, i, chunk(hexlify(t))))
95+
96+
print("%s]," % (pad,))
97+
9898
def tv_str_rust(name, value, pad):
9999
print('''%s%s: "%s",''' % (
100100
pad,
101101
name,
102102
value,
103103
))
104104

105-
def tv_option_bytes_rust(name, value, pad):
106-
if value:
107-
print('''%s%s: Some([
108-
%s%s
109-
%s]),''' % (
110-
pad,
111-
name,
112-
pad,
113-
chunk(hexlify(value.thing)),
114-
pad,
115-
))
116-
else:
117-
print('%s%s: None,' % (pad, name))
118-
119-
def tv_option_vec_bytes_rust(name, value, pad):
105+
def tv_option_bytes_rust(name, value, pad, kind=""):
120106
if value:
121-
print('''%s%s: Some(vec![
107+
print('''%s%s: Some(%s[
122108
%s%s
123109
%s]),''' % (
124110
pad,
125111
name,
112+
kind,
126113
pad,
127114
chunk(hexlify(value.thing)),
128115
pad,
@@ -147,14 +134,20 @@ def tv_part_rust(name, value, config, indent=3):
147134

148135
pad = ' ' * indent
149136
if config['rust_type'] == 'Option<Vec<u8>>':
150-
tv_option_vec_bytes_rust(name, value, pad)
137+
tv_option_bytes_rust(name, value, pad, kind="vec!")
138+
elif config['rust_type'] == 'Option<&\'static [u8]>':
139+
tv_option_bytes_rust(name, value, pad, kind="&")
151140
elif config['rust_type'] == 'Vec<u8>':
152-
tv_vec_bytes_rust(name, value, pad)
141+
tv_bytes_rust(name, value, pad, kind="vec!")
142+
elif config['rust_type'] == '&\'static [u8]':
143+
tv_bytes_rust(name, value, pad, kind="&")
153144
elif config['rust_type'] == 'Vec<bool>':
154145
tv_vec_bool_rust(name, value, pad)
146+
elif config['rust_type'] == '&\'static [(u32, &\'static [u8])]':
147+
tv_tuple_int_bytes_rust(name, value, pad)
155148
elif config['rust_type'] == '&\'static str':
156149
tv_str_rust(name, value, pad)
157-
elif config['rust_type'].startswith('Option<['):
150+
elif config['rust_type'].startswith('Option<[u8'):
158151
tv_option_bytes_rust(name, value, pad)
159152
elif type(value) == bytes:
160153
tv_bytes_rust(name, value, pad)
@@ -166,7 +159,7 @@ def tv_part_rust(name, value, config, indent=3):
166159
print('''%s%s: %s[''' % (
167160
pad,
168161
name,
169-
'vec!' if config['rust_type'].startswith('Vec<') else '',
162+
'vec!' if config['rust_type'].startswith('Vec<') else "&" if config['rust_type'].startswith('&') else '',
170163
))
171164
for item in value:
172165
if 'Vec<u8>' in config['rust_type']:

0 commit comments

Comments
 (0)