@@ -33,24 +33,44 @@ var (
3333)
3434
3535// Parse OpenSSH PrivateKey From PEM
36- func (this SSH ) ParseOpenSSHPrivateKeyFromPEM (key []byte ) (crypto.PrivateKey , string , error ) {
36+ func (this SSH ) ParseOpenSSHPrivateKeyFromPEM (key []byte ) (crypto.PrivateKey , string , string , error ) {
3737 // Parse PEM block
3838 var block * pem.Block
3939 if block , _ = pem .Decode (key ); block == nil {
40- return nil , "" , ErrKeyMustBePEMEncoded
40+ return nil , "" , "" , ErrKeyMustBePEMEncoded
4141 }
4242
43- return ssh .ParseOpenSSHPrivateKey (block .Bytes )
43+ privateKey , comment , err := ssh .ParseOpenSSHPrivateKey (block .Bytes )
44+ if err != nil {
45+ return nil , "" , "" , err
46+ }
47+
48+ info , err := ssh .ParseOpenSSHPrivateKeyToInfo (block .Bytes )
49+ if err != nil {
50+ return nil , "" , "" , err
51+ }
52+
53+ return privateKey , comment , info .CipherName , nil
4454}
4555
4656// Parse OpenSSH PrivateKey From PEM With Password
47- func (this SSH ) ParseOpenSSHPrivateKeyFromPEMWithPassword (key []byte , password []byte ) (crypto.PrivateKey , string , error ) {
57+ func (this SSH ) ParseOpenSSHPrivateKeyFromPEMWithPassword (key []byte , password []byte ) (crypto.PrivateKey , string , string , error ) {
4858 var block * pem.Block
4959 if block , _ = pem .Decode (key ); block == nil {
50- return nil , "" , ErrKeyMustBePEMEncoded
60+ return nil , "" , "" , ErrKeyMustBePEMEncoded
61+ }
62+
63+ privateKey , comment , err := ssh .ParseOpenSSHPrivateKeyWithPassword (block .Bytes , password )
64+ if err != nil {
65+ return nil , "" , "" , err
66+ }
67+
68+ info , err := ssh .ParseOpenSSHPrivateKeyToInfo (block .Bytes )
69+ if err != nil {
70+ return nil , "" , "" , err
5171 }
5272
53- return ssh . ParseOpenSSHPrivateKeyWithPassword ( block . Bytes , password )
73+ return privateKey , comment , info . CipherName , nil
5474}
5575
5676// Parse OpenSSH PublicKey From PEM
0 commit comments