Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: debug with data hex #86

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rust-bindings/bls-signatures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ apple = ["bls-dash-sys/apple"]
bls-dash-sys = { path = "../bls-dash-sys" }
serde = { version= "1.0.160", features = ["derive"], optional = true}
rand = { version= "0.8.5", optional = true}
hex = { version = "0.4.3"}
20 changes: 18 additions & 2 deletions rust-bindings/bls-signatures/src/elements.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::ffi::c_void;
use std::fmt::Debug;
use std::fmt::Formatter;

use bls_dash_sys::{CoreMPLDeriveChildPkUnhardened, G1ElementFree, G1ElementFromBytes, G1ElementGenerator, G1ElementGetFingerprint, G1ElementIsEqual, G1ElementSerialize, G1ElementCopy, G2ElementCopy, G2ElementFree, G2ElementFromBytes, G2ElementIsEqual, G2ElementSerialize, ThresholdPublicKeyRecover, ThresholdSignatureRecover};
#[cfg(feature = "use_serde")]
Expand All @@ -17,7 +19,6 @@ pub type PublicKey = G1Element;
#[cfg(feature = "dash_helpers")]
pub type Signature = G2Element;

#[derive(Debug)]
pub struct G1Element {
pub(crate) c_element: *mut c_void,
}
Expand All @@ -28,6 +29,14 @@ impl PartialEq for G1Element {
}
}

impl Debug for G1Element {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let g1_hex = hex::encode(self.to_bytes().as_slice());

write!(f, "G1Element({:?})", g1_hex)
}
}

impl Eq for G1Element {}

impl G1Element {
Expand Down Expand Up @@ -181,7 +190,6 @@ impl Drop for G1Element {
}
}

#[derive(Debug)]
pub struct G2Element {
pub(crate) c_element: *mut c_void,
}
Expand All @@ -192,6 +200,14 @@ impl PartialEq for G2Element {
}
}

impl Debug for G2Element {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let g2_hex = hex::encode(self.to_bytes().as_slice());

write!(f, "G2Element({:?})", g2_hex)
}
}

impl Eq for G2Element {}

impl G2Element {
Expand Down
9 changes: 8 additions & 1 deletion rust-bindings/bls-signatures/src/private_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::{ffi::c_void, ops::Mul};
use std::fmt::{Debug, Formatter};

use bls_dash_sys::{
CoreMPLDeriveChildSk, CoreMPLDeriveChildSkUnhardened, CoreMPLKeyGen, G1ElementMul,
Expand All @@ -13,7 +14,6 @@ use crate::{schemes::Scheme, utils::{c_err_to_result, SecureBox}, BasicSchemeMPL

pub const PRIVATE_KEY_SIZE: usize = 32; // TODO somehow extract it from bls library

#[derive(Debug)]
pub struct PrivateKey {
pub(crate) c_private_key: *mut c_void,
}
Expand All @@ -26,6 +26,13 @@ impl PartialEq for PrivateKey {

impl Eq for PrivateKey {}

impl Debug for PrivateKey {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let private_key_hex = hex::encode(self.to_bytes().as_slice());

write!(f, "PrivateKey({:?})", private_key_hex)
}
}
impl Mul<G1Element> for PrivateKey {
type Output = Result<G1Element, BlsError>;

Expand Down
Loading