7 MAGIC
= 'SSH PRIVATE KEY FILE FORMAT 1.1\n\0'
8 keyring
, tag
, outfile
= argv
[1:]
9 kf
= C
.KeyFile(keyring
)
13 n
, e
= [kd
[label
].mp
for label
in ['n', 'e']]
15 d
, p
, q
, dp
, dq
, q_inv
= \
16 [priv
[label
].mp
for label
in ['d', 'p', 'q', 'd-mod-p', 'd-mod-q', 'q-inv']]
20 buf
.putu8(0) # symmetric cipher type
21 buf
.putu32(0) # `reserved data'
22 buf
.putu32(n
.nbits
) # `not sure what this is'
23 buf
.putu16(n
.nbits
).put(n
.storeb())
24 buf
.putu16(e
.nbits
).put(e
.storeb())
25 buf
.putblk32(k
.fulltag
) # comment
26 buf
.putu16(1234).putu16(1234)# `next two pairs of characters are identical'
27 buf
.putu16(d
.nbits
).put(d
.storeb())
28 buf
.putu16(q_inv
.nbits
).put(q_inv
.storeb())
29 buf
.putu16(q
.nbits
).put(q
.storeb())
30 buf
.putu16(p
.nbits
).put(p
.storeb())
31 outtmp
= outfile
+ '.new'
32 with
open(outtmp
, 'wb') as f
: f
.write(buf
)
33 OS
.rename(outtmp
, outfile
)