Skip to content

Commit

Permalink
start fixing no_Std
Browse files Browse the repository at this point in the history
  • Loading branch information
burdges committed Apr 30, 2019
1 parent 95393b6 commit 408d1ce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/cert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct ECQVCertSecret(pub [u8; 64]);
/*
impl<'a> From<&'a ECQVCertSecret> for &'a ECQVCertPublic {
from(secret: &ECQVCertSecret) -> &ECQVCertPublic {
unsafe { ::std::mem::transmute(secret) }
unsafe { ::core::mem::transmute(secret) }
}
}
*/
Expand Down
2 changes: 1 addition & 1 deletion src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

//! ### Schnorr signature contexts and configuration, adaptable to most Schnorr signature schemes.

use std::cell::RefCell;
use core::{cell::RefCell};

use rand::prelude::*; // {RngCore,thread_rng};

Expand Down
32 changes: 16 additions & 16 deletions src/musig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@


use core::borrow::{Borrow}; // BorrowMut
use std::collections::BTreeMap;

#[cfg(feature = "alloc")]
use alloc::collections::{BTreeMap, btree_map::Entry};
#[cfg(feature = "std")]
use std::collections::{BTreeMap, btree_map::Entry};


use merlin::Transcript;
use clear_on_drop::clear::Clear;
Expand Down Expand Up @@ -383,10 +388,9 @@ where K: Borrow<Keypair>, T: SigningTranscript
-> SignatureResult<()>
{
let theirs = CoR::Commit(theirs);
use std::collections::btree_map::Entry::*;
match self.Rs.entry(them) {
Vacant(v) => { v.insert(theirs); () },
Occupied(o) =>
Entry::Vacant(v) => { v.insert(theirs); () },
Entry::Occupied(o) =>
if o.get() != &theirs {
let musig_stage = MultiSignatureStage::Commitment;
return Err(SignatureError::MuSigInconsistent { musig_stage, duplicate: true, });
Expand Down Expand Up @@ -433,13 +437,12 @@ where K: Borrow<Keypair>, T: SigningTranscript
pub fn add_their_reveal(&mut self, them: PublicKey, theirs: Reveal)
-> SignatureResult<()>
{
use std::collections::btree_map::Entry::*;
match self.Rs.entry(them) {
Vacant(_) => {
Entry::Vacant(_) => {
let musig_stage = MultiSignatureStage::Commitment;
Err(SignatureError::MuSigAbsent { musig_stage, })
},
Occupied(mut o) => o.get_mut().set_revealed(CompressedRistretto(theirs.0))
Entry::Occupied(mut o) => o.get_mut().set_revealed(CompressedRistretto(theirs.0))
}
}

Expand Down Expand Up @@ -468,10 +471,9 @@ where K: Borrow<Keypair>, T: SigningTranscript
let R = CompressedRistretto(theirs.0).decompress()
.ok_or(SignatureError::PointDecompressionError) ?;
let theirs = CoR::Reveal { R };
use std::collections::btree_map::Entry::*;
match self.Rs.entry(them) {
Vacant(v) => { v.insert(theirs); () },
Occupied(o) =>
Entry::Vacant(v) => { v.insert(theirs); () },
Entry::Occupied(o) =>
if o.get() != &theirs {
let musig_stage = MultiSignatureStage::Reveal;
return Err(SignatureError::MuSigInconsistent { musig_stage, duplicate: true, });
Expand Down Expand Up @@ -528,13 +530,12 @@ impl<T: SigningTranscript> MuSig<T,CosignStage> {
{
let theirs = Scalar::from_canonical_bytes(theirs.0)
.ok_or(SignatureError::ScalarFormatError) ?;
use std::collections::btree_map::Entry::*;
match self.Rs.entry(them) {
Vacant(_) => {
Entry::Vacant(_) => {
let musig_stage = MultiSignatureStage::Reveal;
Err(SignatureError::MuSigAbsent { musig_stage, })
},
Occupied(mut o) => o.get_mut().set_cosigned(theirs)
Entry::Occupied(mut o) => o.get_mut().set_cosigned(theirs)
}
}

Expand Down Expand Up @@ -599,10 +600,9 @@ impl<T: SigningTranscript> MuSig<T,CollectStage> {
.ok_or(SignatureError::ScalarFormatError) ?;
let cor = CoR::Collect { R, s };

use std::collections::btree_map::Entry::*;
match self.Rs.entry(them) {
Vacant(v) => { v.insert(cor); () },
Occupied(o) =>
Entry::Vacant(v) => { v.insert(cor); () },
Entry::Occupied(o) =>
if o.get() != &cor {
let musig_stage = MultiSignatureStage::Reveal;
return Err(SignatureError::MuSigInconsistent { musig_stage, duplicate: true, });
Expand Down

0 comments on commit 408d1ce

Please sign in to comment.