33use std:: { cmp:: Ordering , fmt, str:: FromStr } ;
44
55use ed25519_dalek:: { Signature , SignatureError , Signer , SigningKey , VerifyingKey } ;
6- use iroh_base:: base32;
76use rand_core:: CryptoRngCore ;
87use serde:: { Deserialize , Serialize } ;
98
@@ -160,37 +159,37 @@ impl NamespacePublicKey {
160159
161160impl fmt:: Display for Author {
162161 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
163- write ! ( f, "{}" , base32 :: fmt ( self . to_bytes( ) ) )
162+ write ! ( f, "{}" , hex :: encode ( self . to_bytes( ) ) )
164163 }
165164}
166165
167166impl fmt:: Display for NamespaceSecret {
168167 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
169- write ! ( f, "{}" , base32 :: fmt ( self . to_bytes( ) ) )
168+ write ! ( f, "{}" , hex :: encode ( self . to_bytes( ) ) )
170169 }
171170}
172171
173172impl fmt:: Display for AuthorPublicKey {
174173 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
175- write ! ( f, "{}" , base32 :: fmt ( self . as_bytes( ) ) )
174+ write ! ( f, "{}" , hex :: encode ( self . as_bytes( ) ) )
176175 }
177176}
178177
179178impl fmt:: Display for NamespacePublicKey {
180179 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
181- write ! ( f, "{}" , base32 :: fmt ( self . as_bytes( ) ) )
180+ write ! ( f, "{}" , hex :: encode ( self . as_bytes( ) ) )
182181 }
183182}
184183
185184impl fmt:: Display for AuthorId {
186185 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
187- write ! ( f, "{}" , base32 :: fmt ( self . as_bytes( ) ) )
186+ write ! ( f, "{}" , hex :: encode ( self . as_bytes( ) ) )
188187 }
189188}
190189
191190impl fmt:: Display for NamespaceId {
192191 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
193- write ! ( f, "{}" , base32 :: fmt ( self . as_bytes( ) ) )
192+ write ! ( f, "{}" , hex :: encode ( self . as_bytes( ) ) )
194193 }
195194}
196195
@@ -202,13 +201,13 @@ impl fmt::Debug for NamespaceSecret {
202201
203202impl fmt:: Debug for NamespaceId {
204203 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
205- write ! ( f, "NamespaceId({})" , base32 :: fmt_short ( self . 0 ) )
204+ write ! ( f, "NamespaceId({})" , hex :: encode ( self . 0 ) )
206205 }
207206}
208207
209208impl fmt:: Debug for AuthorId {
210209 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
211- write ! ( f, "AuthorId({})" , base32 :: fmt_short ( self . 0 ) )
210+ write ! ( f, "AuthorId({})" , hex :: encode ( self . 0 ) )
212211 }
213212}
214213
@@ -230,35 +229,41 @@ impl fmt::Debug for AuthorPublicKey {
230229 }
231230}
232231
232+ fn parse_hex_array ( s : & str ) -> anyhow:: Result < [ u8 ; 32 ] > {
233+ let mut bytes = [ 0u8 ; 32 ] ;
234+ hex:: decode_to_slice ( s, & mut bytes) ?;
235+ Ok ( bytes)
236+ }
237+
233238impl FromStr for Author {
234239 type Err = anyhow:: Error ;
235240
236241 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
237- Ok ( Self :: from_bytes ( & base32 :: parse_array ( s) ?) )
242+ Ok ( Self :: from_bytes ( & parse_hex_array ( s) ?) )
238243 }
239244}
240245
241246impl FromStr for NamespaceSecret {
242247 type Err = anyhow:: Error ;
243248
244249 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
245- Ok ( Self :: from_bytes ( & base32 :: parse_array ( s) ?) )
250+ Ok ( Self :: from_bytes ( & parse_hex_array ( s) ?) )
246251 }
247252}
248253
249254impl FromStr for AuthorPublicKey {
250255 type Err = anyhow:: Error ;
251256
252257 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
253- Self :: from_bytes ( & base32 :: parse_array ( s) ?) . map_err ( Into :: into)
258+ Self :: from_bytes ( & parse_hex_array ( s) ?) . map_err ( Into :: into)
254259 }
255260}
256261
257262impl FromStr for NamespacePublicKey {
258263 type Err = anyhow:: Error ;
259264
260265 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
261- Self :: from_bytes ( & base32 :: parse_array ( s) ?) . map_err ( Into :: into)
266+ Self :: from_bytes ( & parse_hex_array ( s) ?) . map_err ( Into :: into)
262267 }
263268}
264269
@@ -386,10 +391,10 @@ impl AuthorId {
386391 AuthorPublicKey :: from_bytes ( & self . 0 )
387392 }
388393
389- /// Convert to a base32 string limited to the first 10 bytes for a friendly string
394+ /// Convert to a hex string limited to the first 10 bytes for a friendly string
390395 /// representation of the key.
391396 pub fn fmt_short ( & self ) -> String {
392- base32 :: fmt_short ( self . 0 )
397+ hex :: encode ( self . 0 ) . chars ( ) . take ( 10 ) . collect ( )
393398 }
394399}
395400
@@ -421,10 +426,10 @@ impl NamespaceId {
421426 NamespacePublicKey :: from_bytes ( & self . 0 )
422427 }
423428
424- /// Convert to a base32 string limited to the first 10 bytes for a friendly string
429+ /// Convert to a hex string limited to the first 10 bytes for a friendly string
425430 /// representation of the key.
426431 pub fn fmt_short ( & self ) -> String {
427- base32 :: fmt_short ( self . 0 )
432+ hex :: encode ( self . 0 ) . chars ( ) . take ( 10 ) . collect ( )
428433 }
429434}
430435
0 commit comments