Skip to content

Commit

Permalink
run rust fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ww3512687 committed May 15, 2024
1 parent 6e15127 commit 73d5c92
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions rust/rust_c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ use ethereum_rust_c;
#[cfg(feature = "multi-coins")]
use near_rust_c;
#[cfg(feature = "multi-coins")]
use signature_rust_c;
#[cfg(feature = "multi-coins")]
use solana_rust_c;
#[cfg(feature = "multi-coins")]
use sui_rust_c;
#[cfg(feature = "multi-coins")]
use tron_rust_c;
#[cfg(feature = "multi-coins")]
use xrp_rust_c;
#[cfg(feature = "multi-coins")]
use signature_rust_c;
7 changes: 3 additions & 4 deletions rust/rust_c/src/signature/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
#![feature(error_in_core)]
#![allow(unused_unsafe)]
extern crate alloc;
mod signature;
mod errors;
mod signature;

use common_rust_c::utils::recover_c_char;
use signature::verify_signature;
use core::slice;
use cty::c_char;
use signature::verify_signature;

#[no_mangle]
pub extern "C" fn verify_frimware_signature(
signature_ptr: *mut c_char,
message_hash_ptr: *mut u8,
pubkey_ptr: *mut u8
pubkey_ptr: *mut u8,
) -> bool {
let signature = recover_c_char(signature_ptr);
let message_hash = unsafe { slice::from_raw_parts(message_hash_ptr, 32) };
Expand All @@ -24,4 +24,3 @@ pub extern "C" fn verify_frimware_signature(
Err(_) => false,
}
}

5 changes: 2 additions & 3 deletions rust/rust_c/src/signature/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ use crate::errors::{Result, RustCError};
use alloc::string::ToString;
use secp256k1::{ecdsa, Message, PublicKey, Secp256k1, SecretKey};


pub fn verify_signature(signature: &[u8], message_hash: &[u8], pubkey: &[u8]) -> Result<bool> {
let secp = Secp256k1::verification_only();
let public_key = PublicKey::from_slice(pubkey)
.map_err(|e| RustCError::FormatTypeError(e.to_string()))?;
let public_key =
PublicKey::from_slice(pubkey).map_err(|e| RustCError::FormatTypeError(e.to_string()))?;
let message = Message::from_slice(message_hash)
.map_err(|e| RustCError::FormatTypeError(e.to_string()))?;
let mut sig = ecdsa::Signature::from_compact(signature)
Expand Down

0 comments on commit 73d5c92

Please sign in to comment.