Skip to content

Commit b520d96

Browse files
committed
Zero is only a little bit positive
1 parent 5959a4f commit b520d96

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

mbedtls/src/bignum/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl ::core::str::FromStr for Mpi {
8383
#[derive(Debug,Copy,Clone,Eq,PartialEq)]
8484
pub enum Sign {
8585
Negative,
86+
Zero,
8687
Positive,
8788
}
8889

@@ -147,8 +148,11 @@ impl Mpi {
147148
}
148149

149150
pub fn sign(&self) -> Sign {
150-
if self.inner.s < 0 {
151+
let cmp = unsafe { mpi_cmp_int(&self.inner, 0) };
152+
if cmp < 0 {
151153
Sign::Negative
154+
} else if cmp == 0 {
155+
Sign::Zero
152156
} else {
153157
Sign::Positive
154158
}

mbedtls/tests/bignum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ const BASE58_ALPHABET: &[u8] = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmno
356356

357357
fn base58_encode(bits: &[u8]) -> mbedtls::Result<String> {
358358
let zero = Mpi::new(0)?;
359-
assert_eq!(zero.sign(), Sign::Positive);
359+
assert_eq!(zero.sign(), Sign::Zero);
360360
let mut n = Mpi::from_binary(bits)?;
361361
let radix: i64 = 58;
362362

0 commit comments

Comments
 (0)