1
- use neon:: prelude:: * ;
2
- use neon:: types:: JsBuffer ;
1
+ use neon:: { prelude:: * , types:: JsBuffer } ;
3
2
use recrypt:: api:: {
4
3
AuthHash , Ed25519Signature , EncryptedMessage , EncryptedTempKey , EncryptedValue , HashedValue ,
5
4
Plaintext , PrivateKey , PublicKey , PublicSigningKey , SchnorrSignature , TransformBlock ,
6
5
TransformKey ,
7
6
} ;
8
7
use recrypt:: nonemptyvec:: NonEmptyVec ;
9
8
10
- ///
11
9
/// Create an `$n` byte fixed u8 array given the provided JsBuffer handle. Throws an error if the provided Buffer
12
10
/// is not of the required length.
13
- ///
14
11
macro_rules! buffer_to_fixed_bytes { ( $( $fn_name: ident, $n: expr) ; * ) => {
15
12
$( pub fn $fn_name<' a, T >( cx: & T , mut buffer: Handle <JsBuffer >, field_name: & str ) -> [ u8 ; $n]
16
13
where T : Context <' a>{
@@ -28,12 +25,8 @@ macro_rules! buffer_to_fixed_bytes { ($($fn_name: ident, $n: expr); *) => {
28
25
// Create the various methods we need to convert buffers into fixed length bytes
29
26
buffer_to_fixed_bytes ! { buffer_to_fixed_32_bytes, 32 ; buffer_to_fixed_64_bytes, 64 ; buffer_to_fixed_128_bytes, 128 ; buffer_to_fixed_384_bytes, 384 }
30
27
31
- ///
32
- /// Create a macro for converting JsBuffers to different types of signature objects which all have the same size. Marked as dead code because usage
33
- /// of this function in the wrapped macro in `api256.rs` can't be parsed by Rust.
34
- ///
28
+ /// Create a macro for converting JsBuffers to different types of signature objects which all have the same size.
35
29
macro_rules! buffer_to_signature { ( $( $fn_name: ident, $sig_type: expr, $ret_type: ty) ; * ) => {
36
- #[ allow( dead_code) ]
37
30
$( pub fn $fn_name<' a, T : Context <' a>>( cx: & T , buffer: Handle <JsBuffer >) -> $ret_type {
38
31
$sig_type( buffer_to_fixed_64_bytes( cx, buffer, "signature" ) )
39
32
} ) +
@@ -42,9 +35,7 @@ macro_rules! buffer_to_signature { ($($fn_name: ident, $sig_type: expr, $ret_typ
42
35
// Create two methods from the macro for Schnorr and ED25519 signatures
43
36
buffer_to_signature ! { buffer_to_schnorr_signature, SchnorrSignature :: new, SchnorrSignature ; buffer_to_ed25519_signature, Ed25519Signature :: new, Ed25519Signature }
44
37
45
- ///
46
38
/// Convert a JsBuffer handle of variable size into a vector
47
- ///
48
39
pub fn buffer_to_variable_bytes < ' a , T : Context < ' a > > (
49
40
cx : & T ,
50
41
mut buffer : Handle < JsBuffer > ,
@@ -54,9 +45,7 @@ pub fn buffer_to_variable_bytes<'a, T: Context<'a>>(
54
45
slice. to_vec ( )
55
46
}
56
47
57
- ///
58
48
/// Copy the bytes from the provided u8 slice into the provided JS Buffer object
59
- ///
60
49
pub fn bytes_to_buffer < ' a , T : Context < ' a > > (
61
50
cx : & mut T ,
62
51
data : & [ u8 ] ,
@@ -68,25 +57,17 @@ pub fn bytes_to_buffer<'a, T: Context<'a>>(
68
57
Ok ( buffer)
69
58
}
70
59
71
- ///
72
60
/// Convert a JsBuffer handle into a PrivateKey
73
- ///
74
61
pub fn buffer_to_private_key < ' a , T : Context < ' a > > ( cx : & T , buffer : Handle < JsBuffer > ) -> PrivateKey {
75
62
PrivateKey :: new ( buffer_to_fixed_32_bytes ( cx, buffer, "privateKey" ) )
76
63
}
77
64
78
- ///
79
- /// Convert a JsBuffer handle to a Plaintext object. Marked as dead code because usage
80
- /// of this function in the wrapped macro in `api256.rs` can't be parsed by Rust
81
- ///
82
- #[ allow( dead_code) ]
65
+ /// Convert a JsBuffer handle to a Plaintext object.
83
66
pub fn buffer_to_plaintext < ' a , T : Context < ' a > > ( cx : & T , buffer : Handle < JsBuffer > ) -> Plaintext {
84
67
Plaintext :: new ( buffer_to_fixed_384_bytes ( cx, buffer, "plaintext" ) )
85
68
}
86
69
87
- ///
88
70
/// Convert a JsObject with x/y Buffers into a PublicKey
89
- ///
90
71
pub fn js_object_to_public_key < ' a , T : Context < ' a > > (
91
72
cx : & mut T ,
92
73
object : Handle < JsObject > ,
@@ -101,9 +82,7 @@ pub fn js_object_to_public_key<'a, T: Context<'a>>(
101
82
. unwrap ( )
102
83
}
103
84
104
- ///
105
85
/// Convert a Recrypt PublicKey struct into a JsObject with x/y properties which are Buffers
106
- ///
107
86
pub fn public_key_to_js_object < ' a , T : Context < ' a > > (
108
87
cx : & mut T ,
109
88
public_key : & PublicKey ,
@@ -118,9 +97,7 @@ pub fn public_key_to_js_object<'a, T: Context<'a>>(
118
97
Ok ( public_key_obj)
119
98
}
120
99
121
- ///
122
100
/// Convert a JsObject which represents a TransformKey into an internal recrypt TransformKey
123
- ///
124
101
pub fn js_object_to_transform_key < ' a , T : Context < ' a > > (
125
102
cx : & mut T ,
126
103
object : Handle < JsObject > ,
@@ -179,9 +156,7 @@ pub fn js_object_to_transform_key<'a, T: Context<'a>>(
179
156
)
180
157
}
181
158
182
- ///
183
159
/// Convert a Recrypt TransformKey into a JsObject with expected properties and bytes converted to Buffers
184
- ///
185
160
pub fn transform_key_to_js_object < ' a , T : Context < ' a > > (
186
161
cx : & mut T ,
187
162
transform_key : TransformKey ,
@@ -206,11 +181,7 @@ pub fn transform_key_to_js_object<'a, T: Context<'a>>(
206
181
Ok ( transform_key_obj)
207
182
}
208
183
209
- ///
210
- /// Convert an array of transform blocks into a non-empty vector of internal recrypt TransformBlock structs. Marked as dead code because usage
211
- /// of this function in the wrapped macro in `api256.rs` can't be parsed by Rust
212
- ///
213
- #[ allow( dead_code) ]
184
+ /// Convert an array of transform blocks into a non-empty vector of internal recrypt TransformBlock structs.
214
185
pub fn js_object_to_transform_blocks < ' a , T : Context < ' a > > (
215
186
cx : & mut T ,
216
187
js_array : Handle < JsArray > ,
@@ -263,11 +234,7 @@ pub fn js_object_to_transform_blocks<'a, T: Context<'a>>(
263
234
NonEmptyVec :: try_from ( & blocks) . unwrap ( )
264
235
}
265
236
266
- ///
267
- /// Iterate through the provided internal TransformBlocks and convert each block to an external array of transform block objects. Marked as dead code because usage
268
- /// of this function in the wrapped macro in `api256.rs` can't be parsed by Rust
269
- ///
270
- #[ allow( dead_code) ]
237
+ /// Iterate through the provided internal TransformBlocks and convert each block to an external array of transform block objects.
271
238
pub fn transform_blocks_to_js_object < ' a , T : Context < ' a > > (
272
239
cx : & mut T ,
273
240
transform_blocks : Vec < TransformBlock > ,
@@ -303,11 +270,7 @@ pub fn transform_blocks_to_js_object<'a, T: Context<'a>>(
303
270
Ok ( blocks_array)
304
271
}
305
272
306
- ///
307
- /// Convert a JsObject with various encrypted value keys into a EncryptedOnce or TransformedValue value. Marked as dead code because usage
308
- /// of this function in the wrapped macro in `api256.rs` can't be parsed by Rust
309
- ///
310
- #[ allow( dead_code) ]
273
+ /// Convert a JsObject with various encrypted value keys into a EncryptedOnce or TransformedValue value.
311
274
pub fn js_object_to_encrypted_value < ' a , T : Context < ' a > > (
312
275
cx : & mut T ,
313
276
object : Handle < JsObject > ,
@@ -380,11 +343,7 @@ pub fn js_object_to_encrypted_value<'a, T: Context<'a>>(
380
343
encrypted_value
381
344
}
382
345
383
- ///
384
- /// Convert a Recrypt EncryptedValue into a JsObbject with expeted properties and bytes converted to Buffers. Marked as dead code because usage
385
- /// of this function in the wrapped macro in `api256.rs` can't be parsed by Rust
386
- ///
387
- #[ allow( dead_code) ]
346
+ /// Convert a Recrypt EncryptedValue into a JsObbject with expeted properties and bytes converted to Buffers.
388
347
pub fn encrypted_value_to_js_object < ' a , T : Context < ' a > > (
389
348
cx : & mut T ,
390
349
encrypted_value : EncryptedValue ,
0 commit comments