3
3
use std:: { cmp:: Ordering , fmt, str:: FromStr } ;
4
4
5
5
use ed25519_dalek:: { Signature , SignatureError , Signer , SigningKey , VerifyingKey } ;
6
- use iroh_base:: base32;
7
6
use rand_core:: CryptoRngCore ;
8
7
use serde:: { Deserialize , Serialize } ;
9
8
@@ -160,37 +159,37 @@ impl NamespacePublicKey {
160
159
161
160
impl fmt:: Display for Author {
162
161
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( ) ) )
164
163
}
165
164
}
166
165
167
166
impl fmt:: Display for NamespaceSecret {
168
167
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( ) ) )
170
169
}
171
170
}
172
171
173
172
impl fmt:: Display for AuthorPublicKey {
174
173
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( ) ) )
176
175
}
177
176
}
178
177
179
178
impl fmt:: Display for NamespacePublicKey {
180
179
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( ) ) )
182
181
}
183
182
}
184
183
185
184
impl fmt:: Display for AuthorId {
186
185
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( ) ) )
188
187
}
189
188
}
190
189
191
190
impl fmt:: Display for NamespaceId {
192
191
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( ) ) )
194
193
}
195
194
}
196
195
@@ -202,13 +201,13 @@ impl fmt::Debug for NamespaceSecret {
202
201
203
202
impl fmt:: Debug for NamespaceId {
204
203
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 ) )
206
205
}
207
206
}
208
207
209
208
impl fmt:: Debug for AuthorId {
210
209
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 ) )
212
211
}
213
212
}
214
213
@@ -230,35 +229,41 @@ impl fmt::Debug for AuthorPublicKey {
230
229
}
231
230
}
232
231
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
+
233
238
impl FromStr for Author {
234
239
type Err = anyhow:: Error ;
235
240
236
241
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) ?) )
238
243
}
239
244
}
240
245
241
246
impl FromStr for NamespaceSecret {
242
247
type Err = anyhow:: Error ;
243
248
244
249
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) ?) )
246
251
}
247
252
}
248
253
249
254
impl FromStr for AuthorPublicKey {
250
255
type Err = anyhow:: Error ;
251
256
252
257
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)
254
259
}
255
260
}
256
261
257
262
impl FromStr for NamespacePublicKey {
258
263
type Err = anyhow:: Error ;
259
264
260
265
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)
262
267
}
263
268
}
264
269
@@ -386,10 +391,10 @@ impl AuthorId {
386
391
AuthorPublicKey :: from_bytes ( & self . 0 )
387
392
}
388
393
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
390
395
/// representation of the key.
391
396
pub fn fmt_short ( & self ) -> String {
392
- base32 :: fmt_short ( self . 0 )
397
+ hex :: encode ( self . 0 ) . chars ( ) . take ( 10 ) . collect ( )
393
398
}
394
399
}
395
400
@@ -421,10 +426,10 @@ impl NamespaceId {
421
426
NamespacePublicKey :: from_bytes ( & self . 0 )
422
427
}
423
428
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
425
430
/// representation of the key.
426
431
pub fn fmt_short ( & self ) -> String {
427
- base32 :: fmt_short ( self . 0 )
432
+ hex :: encode ( self . 0 ) . chars ( ) . take ( 10 ) . collect ( )
428
433
}
429
434
}
430
435
0 commit comments