Skip to content

Commit 9ba7210

Browse files
committed
Cleanup rust bindings serdes. Fix typo in AggregatePublicKey::aggregate
1 parent fb9b3b9 commit 9ba7210

File tree

1 file changed

+9
-21
lines changed

1 file changed

+9
-21
lines changed

bindings/rust/src/lib.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ macro_rules! sig_variant_impl {
462462
}
463463

464464
pub fn uncompress(pk_comp: &[u8]) -> Result<Self, BLST_ERROR> {
465-
if pk_comp.len() == $pk_comp_size {
465+
if pk_comp.len() == $pk_comp_size && (pk_comp[0] & 0x80) != 0 {
466466
let mut pk = <$pk_aff>::default();
467467
let err = unsafe { $pk_uncomp(&mut pk, pk_comp.as_ptr()) };
468468
if err != BLST_ERROR::BLST_SUCCESS {
@@ -475,8 +475,8 @@ macro_rules! sig_variant_impl {
475475
}
476476

477477
pub fn deserialize(pk_in: &[u8]) -> Result<Self, BLST_ERROR> {
478-
if pk_in.len() == $pk_ser_size && (pk_in[0] & 0x80) == 0
479-
|| pk_in.len() == $pk_comp_size && (pk_in[0] & 0x80) != 0
478+
if (pk_in.len() == $pk_ser_size && (pk_in[0] & 0x80) == 0)
479+
|| (pk_in.len() == $pk_comp_size && (pk_in[0] & 0x80) != 0)
480480
{
481481
let mut pk = <$pk_aff>::default();
482482
let err = unsafe { $pk_deser(&mut pk, pk_in.as_ptr()) };
@@ -490,13 +490,7 @@ macro_rules! sig_variant_impl {
490490
}
491491

492492
pub fn from_bytes(pk_in: &[u8]) -> Result<Self, BLST_ERROR> {
493-
if (pk_in[0] & 0x80) == 0 {
494-
// Not compressed
495-
PublicKey::deserialize(pk_in)
496-
} else {
497-
// compressed
498-
PublicKey::uncompress(pk_in)
499-
}
493+
PublicKey::deserialize(pk_in)
500494
}
501495

502496
pub fn to_bytes(&self) -> [u8; $pk_comp_size] {
@@ -552,7 +546,7 @@ macro_rules! sig_variant_impl {
552546
let mut agg_pk = AggregatePublicKey::from_public_key(pks[0]);
553547
for s in pks.iter().skip(1) {
554548
if pks_validate {
555-
pks[0].validate()?;
549+
s.validate()?;
556550
}
557551
unsafe {
558552
$pk_add_or_dbl_aff(
@@ -952,7 +946,7 @@ macro_rules! sig_variant_impl {
952946
}
953947

954948
pub fn uncompress(sig_comp: &[u8]) -> Result<Self, BLST_ERROR> {
955-
if sig_comp.len() == $sig_comp_size {
949+
if sig_comp.len() == $sig_comp_size && (sig_comp[0] & 0x80) != 0 {
956950
let mut sig = <$sig_aff>::default();
957951
let err =
958952
unsafe { $sig_uncomp(&mut sig, sig_comp.as_ptr()) };
@@ -966,8 +960,8 @@ macro_rules! sig_variant_impl {
966960
}
967961

968962
pub fn deserialize(sig_in: &[u8]) -> Result<Self, BLST_ERROR> {
969-
if sig_in.len() == $sig_ser_size && (sig_in[0] & 0x80) == 0
970-
|| sig_in.len() == $sig_comp_size && (sig_in[0] & 0x80) != 0
963+
if (sig_in.len() == $sig_ser_size && (sig_in[0] & 0x80) == 0)
964+
|| (sig_in.len() == $sig_comp_size && (sig_in[0] & 0x80) != 0)
971965
{
972966
let mut sig = <$sig_aff>::default();
973967
let err = unsafe { $sig_deser(&mut sig, sig_in.as_ptr()) };
@@ -981,13 +975,7 @@ macro_rules! sig_variant_impl {
981975
}
982976

983977
pub fn from_bytes(sig_in: &[u8]) -> Result<Self, BLST_ERROR> {
984-
if (sig_in[0] & 0x80) == 0 {
985-
// Not compressed
986-
Signature::deserialize(sig_in)
987-
} else {
988-
// compressed
989-
Signature::uncompress(sig_in)
990-
}
978+
Signature::deserialize(sig_in)
991979
}
992980

993981
pub fn to_bytes(&self) -> [u8; $sig_comp_size] {

0 commit comments

Comments
 (0)