1- use neon:: prelude:: * ;
2- use neon:: types:: JsBuffer ;
1+ use neon:: { prelude:: * , types:: JsBuffer } ;
32use recrypt:: api:: {
43 AuthHash , Ed25519Signature , EncryptedMessage , EncryptedTempKey , EncryptedValue , HashedValue ,
54 Plaintext , PrivateKey , PublicKey , PublicSigningKey , SchnorrSignature , TransformBlock ,
65 TransformKey ,
76} ;
87use recrypt:: nonemptyvec:: NonEmptyVec ;
98
10- ///
119/// Create an `$n` byte fixed u8 array given the provided JsBuffer handle. Throws an error if the provided Buffer
1210/// is not of the required length.
13- ///
1411macro_rules! buffer_to_fixed_bytes { ( $( $fn_name: ident, $n: expr) ; * ) => {
1512 $( pub fn $fn_name<' a, T >( cx: & T , mut buffer: Handle <JsBuffer >, field_name: & str ) -> [ u8 ; $n]
1613 where T : Context <' a>{
@@ -28,12 +25,8 @@ macro_rules! buffer_to_fixed_bytes { ($($fn_name: ident, $n: expr); *) => {
2825// Create the various methods we need to convert buffers into fixed length bytes
2926buffer_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 }
3027
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.
3529macro_rules! buffer_to_signature { ( $( $fn_name: ident, $sig_type: expr, $ret_type: ty) ; * ) => {
36- #[ allow( dead_code) ]
3730 $( pub fn $fn_name<' a, T : Context <' a>>( cx: & T , buffer: Handle <JsBuffer >) -> $ret_type {
3831 $sig_type( buffer_to_fixed_64_bytes( cx, buffer, "signature" ) )
3932 } ) +
@@ -42,9 +35,7 @@ macro_rules! buffer_to_signature { ($($fn_name: ident, $sig_type: expr, $ret_typ
4235// Create two methods from the macro for Schnorr and ED25519 signatures
4336buffer_to_signature ! { buffer_to_schnorr_signature, SchnorrSignature :: new, SchnorrSignature ; buffer_to_ed25519_signature, Ed25519Signature :: new, Ed25519Signature }
4437
45- ///
4638/// Convert a JsBuffer handle of variable size into a vector
47- ///
4839pub fn buffer_to_variable_bytes < ' a , T : Context < ' a > > (
4940 cx : & T ,
5041 mut buffer : Handle < JsBuffer > ,
@@ -54,9 +45,7 @@ pub fn buffer_to_variable_bytes<'a, T: Context<'a>>(
5445 slice. to_vec ( )
5546}
5647
57- ///
5848/// Copy the bytes from the provided u8 slice into the provided JS Buffer object
59- ///
6049pub fn bytes_to_buffer < ' a , T : Context < ' a > > (
6150 cx : & mut T ,
6251 data : & [ u8 ] ,
@@ -68,25 +57,17 @@ pub fn bytes_to_buffer<'a, T: Context<'a>>(
6857 Ok ( buffer)
6958}
7059
71- ///
7260/// Convert a JsBuffer handle into a PrivateKey
73- ///
7461pub fn buffer_to_private_key < ' a , T : Context < ' a > > ( cx : & T , buffer : Handle < JsBuffer > ) -> PrivateKey {
7562 PrivateKey :: new ( buffer_to_fixed_32_bytes ( cx, buffer, "privateKey" ) )
7663}
7764
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.
8366pub fn buffer_to_plaintext < ' a , T : Context < ' a > > ( cx : & T , buffer : Handle < JsBuffer > ) -> Plaintext {
8467 Plaintext :: new ( buffer_to_fixed_384_bytes ( cx, buffer, "plaintext" ) )
8568}
8669
87- ///
8870/// Convert a JsObject with x/y Buffers into a PublicKey
89- ///
9071pub fn js_object_to_public_key < ' a , T : Context < ' a > > (
9172 cx : & mut T ,
9273 object : Handle < JsObject > ,
@@ -101,9 +82,7 @@ pub fn js_object_to_public_key<'a, T: Context<'a>>(
10182 . unwrap ( )
10283}
10384
104- ///
10585/// Convert a Recrypt PublicKey struct into a JsObject with x/y properties which are Buffers
106- ///
10786pub fn public_key_to_js_object < ' a , T : Context < ' a > > (
10887 cx : & mut T ,
10988 public_key : & PublicKey ,
@@ -118,9 +97,7 @@ pub fn public_key_to_js_object<'a, T: Context<'a>>(
11897 Ok ( public_key_obj)
11998}
12099
121- ///
122100/// Convert a JsObject which represents a TransformKey into an internal recrypt TransformKey
123- ///
124101pub fn js_object_to_transform_key < ' a , T : Context < ' a > > (
125102 cx : & mut T ,
126103 object : Handle < JsObject > ,
@@ -179,9 +156,7 @@ pub fn js_object_to_transform_key<'a, T: Context<'a>>(
179156 )
180157}
181158
182- ///
183159/// Convert a Recrypt TransformKey into a JsObject with expected properties and bytes converted to Buffers
184- ///
185160pub fn transform_key_to_js_object < ' a , T : Context < ' a > > (
186161 cx : & mut T ,
187162 transform_key : TransformKey ,
@@ -206,11 +181,7 @@ pub fn transform_key_to_js_object<'a, T: Context<'a>>(
206181 Ok ( transform_key_obj)
207182}
208183
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.
214185pub fn js_object_to_transform_blocks < ' a , T : Context < ' a > > (
215186 cx : & mut T ,
216187 js_array : Handle < JsArray > ,
@@ -263,11 +234,7 @@ pub fn js_object_to_transform_blocks<'a, T: Context<'a>>(
263234 NonEmptyVec :: try_from ( & blocks) . unwrap ( )
264235}
265236
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.
271238pub fn transform_blocks_to_js_object < ' a , T : Context < ' a > > (
272239 cx : & mut T ,
273240 transform_blocks : Vec < TransformBlock > ,
@@ -303,11 +270,7 @@ pub fn transform_blocks_to_js_object<'a, T: Context<'a>>(
303270 Ok ( blocks_array)
304271}
305272
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.
311274pub fn js_object_to_encrypted_value < ' a , T : Context < ' a > > (
312275 cx : & mut T ,
313276 object : Handle < JsObject > ,
@@ -380,11 +343,7 @@ pub fn js_object_to_encrypted_value<'a, T: Context<'a>>(
380343 encrypted_value
381344}
382345
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.
388347pub fn encrypted_value_to_js_object < ' a , T : Context < ' a > > (
389348 cx : & mut T ,
390349 encrypted_value : EncryptedValue ,
0 commit comments