@@ -1582,15 +1582,15 @@ impl<'de> Deserialize<'de> for CommitOid {
15821582/// Error type for `PublicKeyHex` construction.
15831583#[ derive( Debug , Clone , PartialEq , Eq , thiserror:: Error ) ]
15841584pub enum PublicKeyHexError {
1585- /// The hex string has the wrong length (not 64 chars / 32 bytes ).
1586- #[ error( "expected 64 hex chars (32 bytes) , got {0} chars" ) ]
1585+ /// The hex string has the wrong length (not 64 or 66 chars ).
1586+ #[ error( "expected 64 (Ed25519) or 66 (P-256) hex chars , got {0} chars" ) ]
15871587 InvalidLength ( usize ) ,
15881588 /// The string contains non-hex characters.
15891589 #[ error( "invalid hex: {0}" ) ]
15901590 InvalidHex ( String ) ,
15911591}
15921592
1593- /// A validated hex-encoded Ed25519 public key (64 hex chars = 32 bytes ).
1593+ /// A validated hex-encoded public key (64 hex chars for Ed25519, 66 for P-256 compressed ).
15941594///
15951595/// Use `to_ed25519()` to convert to the byte-array `Ed25519PublicKey` type.
15961596#[ derive( Debug , Clone , PartialEq , Eq , Hash , Serialize ) ]
@@ -1612,7 +1612,7 @@ impl PublicKeyHex {
16121612 pub fn parse ( raw : & str ) -> Result < Self , PublicKeyHexError > {
16131613 let s = raw. trim ( ) . to_lowercase ( ) ;
16141614 let bytes = hex:: decode ( & s) . map_err ( |e| PublicKeyHexError :: InvalidHex ( e. to_string ( ) ) ) ?;
1615- if bytes. len ( ) != 32 {
1615+ if bytes. len ( ) != 32 && bytes . len ( ) != 33 {
16161616 return Err ( PublicKeyHexError :: InvalidLength ( s. len ( ) ) ) ;
16171617 }
16181618 Ok ( Self ( s) )
0 commit comments