@@ -51,7 +51,7 @@ module.exports = {
51
51
//keynum
52
52
reader . off += 4 ;
53
53
54
- //sshpublengtn
54
+ //sshpublength
55
55
reader . off += 4 ;
56
56
57
57
//keytype
@@ -88,10 +88,29 @@ module.exports = {
88
88
dq . toBuffer ( ) , // exponent2 -- d mod (q-1)
89
89
coeff // coefficient -- (inverse of q) mod p
90
90
) ;
91
+
92
+ key . sshcomment = readOpenSSHKeyString ( reader ) . toString ( 'ascii' ) ;
91
93
} ,
92
94
93
95
publicExport : function ( key , options ) {
94
- throw Error ( 'Not implemented yet.' ) ;
96
+ let ebuf = Buffer . alloc ( 4 )
97
+ ebuf . writeUInt32BE ( key . e , 0 ) ;
98
+ //Slice leading zeroes
99
+ while ( ebuf [ 0 ] === 0 ) ebuf = ebuf . slice ( 1 ) ;
100
+ const nbuf = key . n . toBuffer ( ) ;
101
+ const buf = Buffer . alloc (
102
+ ebuf . byteLength + 4 +
103
+ nbuf . byteLength + 4 +
104
+ 'ssh-rsa' . length + 4
105
+ ) ;
106
+
107
+ const writer = { buf : buf , off : 0 } ;
108
+ writeOpenSSHKeyString ( writer , Buffer . from ( 'ssh-rsa' ) ) ;
109
+ writeOpenSSHKeyString ( writer , ebuf ) ;
110
+ writeOpenSSHKeyString ( writer , nbuf ) ;
111
+
112
+ let comment = key . sshcomment || '' ;
113
+ return 'ssh-rsa ' + buf . toString ( 'base64' ) + ' ' + comment ;
95
114
} ,
96
115
97
116
publicImport : function ( key , data , options ) {
@@ -161,4 +180,10 @@ function readOpenSSHKeyString(reader) {
161
180
const res = reader . buf . slice ( reader . off , reader . off + len ) ;
162
181
reader . off += len ;
163
182
return res ;
183
+ }
184
+
185
+ function writeOpenSSHKeyString ( writer , data ) {
186
+ writer . buf . writeInt32BE ( data . byteLength , writer . off ) ;
187
+ writer . off += 4 ;
188
+ writer . off += data . copy ( writer . buf , writer . off ) ;
164
189
}
0 commit comments