27
27
//! println!(" * Pubkey #{} -> {}", i + 1, pubkey.to_fingerprint_string());
28
28
//! }
29
29
//! }
30
+ #![ cfg_attr( not( any( feature = "std" , test) ) , no_std) ]
31
+
32
+ extern crate alloc;
30
33
31
34
mod reader;
32
35
mod writer;
33
36
34
37
pub mod errors {
35
38
use thiserror:: Error ;
36
39
37
- pub type Result < T > = std:: result:: Result < T , OpenSSHKeyError > ;
40
+ use alloc:: string:: String ;
41
+
42
+ pub type Result < T > = core:: result:: Result < T , OpenSSHKeyError > ;
38
43
39
44
#[ derive( Error , Debug ) ]
40
45
pub enum OpenSSHKeyError {
46
+ #[ cfg( any( feature = "std" , test, doc) ) ]
41
47
#[ error( "I/O error" ) ]
42
48
IO {
43
49
#[ from]
@@ -47,7 +53,7 @@ pub mod errors {
47
53
#[ error( "invalid UTF-8" ) ]
48
54
InvalidUtf8 {
49
55
#[ from]
50
- source : std :: str:: Utf8Error ,
56
+ source : core :: str:: Utf8Error ,
51
57
} ,
52
58
53
59
// keep base64::DecodeError out of the public API
@@ -74,8 +80,12 @@ use sha2::{Digest, Sha256};
74
80
use crate :: reader:: Reader ;
75
81
use crate :: writer:: Writer ;
76
82
77
- use std:: fmt;
78
- use std:: io:: { BufRead , BufReader , Read } ;
83
+ use core:: fmt;
84
+
85
+ use alloc:: borrow:: ToOwned ;
86
+ use alloc:: format;
87
+ use alloc:: string:: { String , ToString } ;
88
+ use alloc:: vec:: Vec ;
79
89
80
90
const SSH_RSA : & str = "ssh-rsa" ;
81
91
const SSH_DSA : & str = "ssh-dss" ;
@@ -185,7 +195,7 @@ impl core::cmp::PartialEq for PublicKey {
185
195
}
186
196
}
187
197
188
- impl std :: str:: FromStr for PublicKey {
198
+ impl core :: str:: FromStr for PublicKey {
189
199
type Err = OpenSSHKeyError ;
190
200
fn from_str ( s : & str ) -> Result < Self > {
191
201
PublicKey :: parse ( s)
@@ -398,13 +408,15 @@ impl PublicKey {
398
408
/// read_keys takes a reader and parses it as an authorized_keys file. it
399
409
/// returns an error if it can't read or parse any of the public keys in the
400
410
/// list.
411
+ #[ cfg( any( feature = "std" , test, doc) ) ]
401
412
pub fn read_keys < R > ( r : R ) -> Result < Vec < Self > >
402
413
where
403
- R : Read ,
414
+ R : std :: io :: Read ,
404
415
{
416
+ use std:: io:: { BufRead , BufReader } ;
405
417
let keybuf = BufReader :: new ( r) ;
406
418
// authorized_keys files are newline-separated lists of public keys
407
- let mut keys = vec ! [ ] ;
419
+ let mut keys = Vec :: new ( ) ;
408
420
for key in keybuf. lines ( ) {
409
421
let key = key?;
410
422
// skip any empty lines and any comment lines (prefixed with '#')
0 commit comments