@@ -18,6 +18,7 @@ use std::cmp;
18
18
19
19
use bitcoin:: secp256k1:: Signature ;
20
20
use bitcoin:: secp256k1:: key:: { PublicKey , SecretKey } ;
21
+ use bitcoin:: secp256k1:: constants:: { PUBLIC_KEY_SIZE , COMPACT_SIGNATURE_SIZE } ;
21
22
use bitcoin:: blockdata:: script:: Script ;
22
23
use bitcoin:: blockdata:: transaction:: { OutPoint , Transaction , TxOut } ;
23
24
use bitcoin:: consensus;
@@ -423,8 +424,8 @@ impl_array!(4); // for IPv4
423
424
impl_array ! ( 10 ) ; // for OnionV2
424
425
impl_array ! ( 16 ) ; // for IPv6
425
426
impl_array ! ( 32 ) ; // for channel id & hmac
426
- impl_array ! ( 33 ) ; // for PublicKey
427
- impl_array ! ( 64 ) ; // for Signature
427
+ impl_array ! ( PUBLIC_KEY_SIZE ) ; // for PublicKey
428
+ impl_array ! ( COMPACT_SIGNATURE_SIZE ) ; // for Signature
428
429
impl_array ! ( 1300 ) ; // for OnionPacket.hop_data
429
430
430
431
// HashMap
@@ -493,7 +494,7 @@ impl Readable for Vec<Signature> {
493
494
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
494
495
let len: u16 = Readable :: read ( r) ?;
495
496
let byte_size = ( len as usize )
496
- . checked_mul ( 33 )
497
+ . checked_mul ( COMPACT_SIGNATURE_SIZE )
497
498
. ok_or ( DecodeError :: BadLengthDescriptor ) ?;
498
499
if byte_size > MAX_BUF_SIZE {
499
500
return Err ( DecodeError :: BadLengthDescriptor ) ;
@@ -528,7 +529,7 @@ impl Writeable for PublicKey {
528
529
529
530
impl Readable for PublicKey {
530
531
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
531
- let buf: [ u8 ; 33 ] = Readable :: read ( r) ?;
532
+ let buf: [ u8 ; PUBLIC_KEY_SIZE ] = Readable :: read ( r) ?;
532
533
match PublicKey :: from_slice ( & buf) {
533
534
Ok ( key) => Ok ( key) ,
534
535
Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
@@ -577,7 +578,7 @@ impl Writeable for Signature {
577
578
578
579
impl Readable for Signature {
579
580
fn read < R : Read > ( r : & mut R ) -> Result < Self , DecodeError > {
580
- let buf: [ u8 ; 64 ] = Readable :: read ( r) ?;
581
+ let buf: [ u8 ; COMPACT_SIGNATURE_SIZE ] = Readable :: read ( r) ?;
581
582
match Signature :: from_compact ( & buf) {
582
583
Ok ( sig) => Ok ( sig) ,
583
584
Err ( _) => return Err ( DecodeError :: InvalidValue ) ,
0 commit comments