@@ -351,24 +351,22 @@ pub enum MalformedKeyDataKind {
351
351
352
352
impl fmt:: Display for MalformedKeyDataKind {
353
353
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
354
- use MalformedKeyDataKind :: * ;
355
-
356
354
let err = match self {
357
- EmptyKey => "empty key" ,
358
- EncounteredUnprintableCharacter => "encountered an unprintable character" ,
359
- InvalidFullPublicKeyPrefix => "only full public keys with prefixes '02', '03' or '04' are allowed" ,
360
- InvalidMasterFingerprintLength => "master fingerprint should be 8 characters long" ,
361
- InvalidMultiIndexStep => "invalid multi index step in multipath descriptor" ,
362
- InvalidMultiXKeyDerivation => "can't make a multi-xpriv with hardened derivation steps that are not shared among all paths into a public key" ,
363
- InvalidPublicKeyLength => "public keys must be 64, 66 or 130 characters in size" ,
364
- InvalidWildcardInDerivationPath => "'*' may only appear as last element in a derivation path" ,
365
- KeyTooShort => "key too short" ,
366
- MultipleFingerprintsInPublicKey => "multiple ']' in Descriptor Public Key" ,
367
- MultipleDerivationPathIndexSteps => "'<' may only appear once in a derivation path" ,
368
- NoKeyAfterOrigin => "no key after origin" ,
369
- NoMasterFingerprintFound => "no master fingerprint found after '['" ,
370
- UnclosedSquareBracket => "unclosed '['" ,
371
- WildcardAsDerivedDescriptorKey => "cannot parse key with a wilcard as a DerivedDescriptorKey" ,
355
+ Self :: EmptyKey => "empty key" ,
356
+ Self :: EncounteredUnprintableCharacter => "encountered an unprintable character" ,
357
+ Self :: InvalidFullPublicKeyPrefix => "only full public keys with prefixes '02', '03' or '04' are allowed" ,
358
+ Self :: InvalidMasterFingerprintLength => "master fingerprint should be 8 characters long" ,
359
+ Self :: InvalidMultiIndexStep => "invalid multi index step in multipath descriptor" ,
360
+ Self :: InvalidMultiXKeyDerivation => "can't make a multi-xpriv with hardened derivation steps that are not shared among all paths into a public key" ,
361
+ Self :: InvalidPublicKeyLength => "public keys must be 64, 66 or 130 characters in size" ,
362
+ Self :: InvalidWildcardInDerivationPath => "'*' may only appear as last element in a derivation path" ,
363
+ Self :: KeyTooShort => "key too short" ,
364
+ Self :: MultipleFingerprintsInPublicKey => "multiple ']' in Descriptor Public Key" ,
365
+ Self :: MultipleDerivationPathIndexSteps => "'<' may only appear once in a derivation path" ,
366
+ Self :: NoKeyAfterOrigin => "no key after origin" ,
367
+ Self :: NoMasterFingerprintFound => "no master fingerprint found after '['" ,
368
+ Self :: UnclosedSquareBracket => "unclosed '['" ,
369
+ Self :: WildcardAsDerivedDescriptorKey => "cannot parse key with a wilcard as a DerivedDescriptorKey" ,
372
370
} ;
373
371
374
372
f. write_str ( err)
@@ -414,72 +412,54 @@ pub enum DescriptorKeyParseError {
414
412
impl fmt:: Display for DescriptorKeyParseError {
415
413
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
416
414
match self {
417
- DescriptorKeyParseError :: Bip32Xpriv ( err) => {
418
- write ! ( f, "error while parsing BIP32 Xpriv: {err}" )
419
- }
420
- DescriptorKeyParseError :: Bip32Xpub ( err) => {
421
- write ! ( f, "error while parsing BIP32 Xpub: {err}" )
422
- }
423
- DescriptorKeyParseError :: DerivationIndexError { index, err } => {
424
- write ! ( f, "error while parsing derivation index '{index}': {err}" )
425
- }
426
- DescriptorKeyParseError :: DeriveHardenedKey ( err) => {
427
- write ! ( f, "unable to derive the hardened steps: {err}" )
428
- }
429
- DescriptorKeyParseError :: MalformedKeyData ( err) => {
430
- write ! ( f, "{err}" )
431
- }
432
- DescriptorKeyParseError :: MasterDerivationPath ( err) => {
433
- write ! ( f, "error while parsing master derivation path: {err}" )
434
- }
435
- DescriptorKeyParseError :: MasterFingerprint { fingerprint, err } => {
436
- write ! ( f, "error while parsing master fingerprint '{fingerprint}': {err}" )
437
- }
438
- DescriptorKeyParseError :: FullPublicKey ( err) => {
439
- write ! ( f, "error while parsing full public key: {err}" )
415
+ Self :: Bip32Xpriv ( err) => err. fmt ( f) ,
416
+ Self :: Bip32Xpub ( err) => err. fmt ( f) ,
417
+ Self :: DerivationIndexError { index, err } => {
418
+ write ! ( f, "at derivation index '{index}': {err}" )
440
419
}
441
- DescriptorKeyParseError :: WifPrivateKey ( err) => {
442
- write ! ( f , "error while parsing WIF private key: { err}" )
443
- }
444
- DescriptorKeyParseError :: XonlyPublicKey ( err) => {
445
- write ! ( f, "error while parsing xonly public key : {err}" )
420
+ Self :: DeriveHardenedKey ( err) => err . fmt ( f ) ,
421
+ Self :: MalformedKeyData ( err ) => err. fmt ( f ) ,
422
+ Self :: MasterDerivationPath ( err ) => err . fmt ( f ) ,
423
+ Self :: MasterFingerprint { fingerprint , err } => {
424
+ write ! ( f, "on master fingerprint '{fingerprint}' : {err}" )
446
425
}
426
+ Self :: FullPublicKey ( err) => err. fmt ( f) ,
427
+ Self :: WifPrivateKey ( err) => err. fmt ( f) ,
428
+ Self :: XonlyPublicKey ( err) => err. fmt ( f) ,
447
429
}
448
430
}
449
431
}
450
432
451
433
#[ cfg( feature = "std" ) ]
452
434
impl error:: Error for DescriptorKeyParseError {
453
435
fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
454
- use DescriptorKeyParseError :: * ;
455
-
456
436
match self {
457
- Bip32Xpriv ( err)
458
- | Bip32Xpub ( err)
459
- | DerivationIndexError { err, .. }
460
- | DeriveHardenedKey ( err)
461
- | MasterDerivationPath ( err) => Some ( err) ,
462
- MasterFingerprint { err, .. } => Some ( err) ,
463
- FullPublicKey ( err) => Some ( err) ,
464
- WifPrivateKey ( err) => Some ( err) ,
465
- XonlyPublicKey ( err) => Some ( err) ,
466
- MalformedKeyData ( _) => None ,
437
+ Self :: Bip32Xpriv ( err)
438
+ | Self :: Bip32Xpub ( err)
439
+ | Self :: DerivationIndexError { err, .. }
440
+ | Self :: DeriveHardenedKey ( err)
441
+ | Self :: MasterDerivationPath ( err) => Some ( err) ,
442
+ Self :: MasterFingerprint { err, .. } => Some ( err) ,
443
+ Self :: FullPublicKey ( err) => Some ( err) ,
444
+ Self :: WifPrivateKey ( err) => Some ( err) ,
445
+ Self :: XonlyPublicKey ( err) => Some ( err) ,
446
+ Self :: MalformedKeyData ( _) => None ,
467
447
}
468
448
}
469
449
}
470
450
471
451
impl fmt:: Display for DescriptorPublicKey {
472
452
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
473
453
match * self {
474
- DescriptorPublicKey :: Single ( ref pk) => {
454
+ Self :: Single ( ref pk) => {
475
455
maybe_fmt_master_id ( f, & pk. origin ) ?;
476
456
match pk. key {
477
457
SinglePubKey :: FullKey ( full_key) => full_key. fmt ( f) ,
478
458
SinglePubKey :: XOnly ( x_only_key) => x_only_key. fmt ( f) ,
479
459
} ?;
480
460
Ok ( ( ) )
481
461
}
482
- DescriptorPublicKey :: XPub ( ref xpub) => {
462
+ Self :: XPub ( ref xpub) => {
483
463
maybe_fmt_master_id ( f, & xpub. origin ) ?;
484
464
xpub. xkey . fmt ( f) ?;
485
465
fmt_derivation_path ( f, & xpub. derivation_path ) ?;
@@ -490,7 +470,7 @@ impl fmt::Display for DescriptorPublicKey {
490
470
}
491
471
Ok ( ( ) )
492
472
}
493
- DescriptorPublicKey :: MultiXPub ( ref xpub) => {
473
+ Self :: MultiXPub ( ref xpub) => {
494
474
maybe_fmt_master_id ( f, & xpub. origin ) ?;
495
475
xpub. xkey . fmt ( f) ?;
496
476
fmt_derivation_paths ( f, xpub. derivation_paths . paths ( ) ) ?;
@@ -694,19 +674,17 @@ pub enum ConversionError {
694
674
impl fmt:: Display for ConversionError {
695
675
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
696
676
f. write_str ( match * self {
697
- ConversionError :: HardenedChild => "hardened child step in bip32 path" ,
698
- ConversionError :: MultiKey => "multiple existing keys" ,
677
+ Self :: HardenedChild => "hardened child step in bip32 path" ,
678
+ Self :: MultiKey => "multiple existing keys" ,
699
679
} )
700
680
}
701
681
}
702
682
703
683
#[ cfg( feature = "std" ) ]
704
684
impl error:: Error for ConversionError {
705
685
fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
706
- use self :: ConversionError :: * ;
707
-
708
686
match self {
709
- HardenedChild | MultiKey => None ,
687
+ Self :: HardenedChild | Self :: MultiKey => None ,
710
688
}
711
689
}
712
690
}
@@ -1399,14 +1377,14 @@ mod test {
1399
1377
let desc = "[NonHexor]xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL/1/*" ;
1400
1378
assert_eq ! (
1401
1379
DescriptorPublicKey :: from_str( desc) . unwrap_err( ) . to_string( ) ,
1402
- "error while parsing master fingerprint 'NonHexor': failed to parse hex digit"
1380
+ "on master fingerprint 'NonHexor': failed to parse hex digit"
1403
1381
) ;
1404
1382
1405
1383
// And ones with invalid xpubs..
1406
1384
let desc = "[78412e3a]xpub1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaLcgJvLJuZZvRcEL/1/*" ;
1407
1385
assert_eq ! (
1408
1386
DescriptorPublicKey :: from_str( desc) . unwrap_err( ) . to_string( ) ,
1409
- "error while parsing BIP32 Xpub: base58 encoding error"
1387
+ "base58 encoding error"
1410
1388
) ;
1411
1389
1412
1390
// ..or invalid raw keys
@@ -1446,22 +1424,19 @@ mod test {
1446
1424
DescriptorSecretKey :: from_str( secret_key)
1447
1425
. unwrap_err( )
1448
1426
. to_string( ) ,
1449
- "error while parsing BIP32 Xpriv: unknown version magic bytes: [4, 136, 178, 30]"
1427
+ "unknown version magic bytes: [4, 136, 178, 30]"
1450
1428
) ;
1451
1429
1452
1430
// And ones with invalid fingerprints
1453
1431
let desc = "[NonHexor]tprv8ZgxMBicQKsPcwcD4gSnMti126ZiETsuX7qwrtMypr6FBwAP65puFn4v6c3jrN9VwtMRMph6nyT63NrfUL4C3nBzPcduzVSuHD7zbX2JKVc/1/*" ;
1454
1432
assert_eq ! (
1455
1433
DescriptorSecretKey :: from_str( desc) . unwrap_err( ) . to_string( ) ,
1456
- "error while parsing master fingerprint 'NonHexor': failed to parse hex digit"
1434
+ "on master fingerprint 'NonHexor': failed to parse hex digit"
1457
1435
) ;
1458
1436
1459
1437
// ..or invalid raw keys
1460
1438
let desc = "[78412e3a]L32jTfVLei6BYTPUpwpJSkrHx8iL9GZzeErVS8y4Y/1/*" ;
1461
- assert_eq ! (
1462
- DescriptorSecretKey :: from_str( desc) . unwrap_err( ) . to_string( ) ,
1463
- "error while parsing WIF private key: invalid base58"
1464
- ) ;
1439
+ assert_eq ! ( DescriptorSecretKey :: from_str( desc) . unwrap_err( ) . to_string( ) , "invalid base58" ) ;
1465
1440
}
1466
1441
1467
1442
#[ test]
0 commit comments