Skip to content

Commit 256be67

Browse files
committed
Convert all .unwraps()s that don't change signatures nor tests
Unwraps that don't change signatures are now converted to being safer. However this is not everything and further work is required. Namely tests are not converted, this would normally be fine, but tests are exported to Elixir and thus have a chance to crash the VM. Further functions like: tests::create_an_action Have non Result outputs, meaning greater refactoring is required to handle these.
1 parent 31fc1c8 commit 256be67

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

arm/src/encryption.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(feature = "nif")]
2+
use crate::rustler_util::{bincode_deserialize, bincode_serialize};
13
use crate::{
24
error::ArmError,
35
utils::{bytes_to_words, words_to_bytes},
@@ -35,7 +37,7 @@ impl SecretKey {
3537

3638
#[cfg(feature = "nif")]
3739
fn do_encode<'a>(secret_key: &SecretKey, env: Env<'a>) -> Result<Term<'a>, Error> {
38-
let bytes = bincode::serialize(&secret_key.0).unwrap();
40+
let bytes = bincode_serialize(&secret_key)?;
3941

4042
let mut erl_bin = OwnedBinary::new(bytes.len()).ok_or(Error::BadArg)?;
4143
let _ = erl_bin.as_mut_slice().write_all(&bytes);

arm/src/rustler_util.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,7 @@ impl RustlerEncoder for AffinePoint {
184184
impl<'a> RustlerDecoder<'a> for AffinePoint {
185185
fn rustler_decode(term: Term<'a>) -> NifResult<Self> {
186186
let binary: Vec<u8> = RustlerDecoder::rustler_decode(term)?;
187-
let affine_point = bincode::deserialize::<AffinePoint>(binary.as_slice());
188-
Ok(affine_point.unwrap())
187+
bincode_deserialize(&binary)
189188
}
190189
}
191190

@@ -200,8 +199,7 @@ impl RustlerEncoder for Signature {
200199
impl<'a> RustlerDecoder<'a> for Signature {
201200
fn rustler_decode(term: Term<'a>) -> NifResult<Self> {
202201
let binary: Vec<u8> = RustlerDecoder::rustler_decode(term)?;
203-
let signature = bincode::deserialize::<Signature>(binary.as_slice());
204-
Ok(signature.unwrap())
202+
bincode_deserialize(&binary)
205203
}
206204
}
207205

0 commit comments

Comments
 (0)