Browse Source

to_dec_string()

pull/8/head
Nanak Nihal Singh Khalsa 1 year ago
parent
commit
c10293fbc4
2 changed files with 15 additions and 4 deletions
  1. +0
    -1
      Cargo.toml
  2. +15
    -3
      src/lib.rs

+ 0
- 1
Cargo.toml

@ -23,7 +23,6 @@ arrayref = "0.3.5"
lazy_static = "1.4.0"
serde = { version = "1.0.152", features = ["derive"] }
bytes = "1.4.0"
rust-gmp = "0.5.0"
[dev-dependencies]
criterion = "0.3"

+ 15
- 3
src/lib.rs

@ -2,6 +2,7 @@
// For LICENSE check https://github.com/arnaucube/babyjubjub-rs
use ff::*;
use num::Num;
use serde::{Serialize, ser::SerializeSeq};
use bytes::{BytesMut, BufMut};
use poseidon_rs::Poseidon;
@ -150,13 +151,24 @@ pub struct Point {
pub y: Fr,
}
pub trait ToDecimalString {
fn to_dec_string(&self) -> String;
}
impl ToDecimalString for Fr {
fn to_dec_string(&self) -> String {
let mut s = self.to_string();
let hex_str = s[5..s.len()-1].to_string();
BigInt::from_str_radix(&hex_str, 16).unwrap().to_string()
}
}
impl Serialize for Point {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer {
let mut seq = serializer.serialize_seq(Some(2))?;
seq.serialize_element(&self.x.to_string())?;
seq.serialize_element(&self.y.to_string())?;
seq.serialize_element(&self.x.to_dec_string())?;
seq.serialize_element(&self.y.to_dec_string())?;
seq.end()
}
}
@ -390,7 +402,7 @@ pub fn decompress_signature(b: &[u8; 64]) -> Result {
Result::Ok(res) => Ok(Signature { r_b8: res, s: s.to_string() }),
}
}
#[derive(Debug)]
#[derive(Debug, Serialize)]
pub struct ElGamalEncryption {
pub c1: Point,
pub c2: Point

Loading…
Cancel
Save