VERSION="0.1.18"
-max_version = 1
+max_version = 2
from sys import version_info
if version_info.major == 2: # for python2
self.d=w[2].base91();
def __str__(self):
return 'make-public("%s","%s")'%(self.a,self.d)
+ def forsites(self,version,xcopy,fs):
+ if version < 2: return []
+ return ['pub', self.a, self.d]
class rsakey (pubkey):
"An RSA public key"
self.e=w[2].bignum_10('rsa','rsa e')
self.n=w[3].bignum_10('rsa','rsa n')
if len(w) >= 5: w[4].email()
+ self.a='rsa1'
+ self.d=base91s_encode(b'%d %s %s' %
+ (self.l,
+ self.e.encode('ascii'),
+ self.n.encode('ascii')))
+ # ^ this allows us to use the pubkey.forsites()
+ # method for output in versions>=2
def __str__(self):
return 'rsa-public("%s","%s")'%(self.e,self.n)
# this specialisation means we can generate files
# compatible with old secnet executables
-
+ def forsites(self,version,xcopy,fs):
+ if version < 2:
+ return ['pubkey', str(self.l), self.e, self.n]
+ return pubkey.forsites(self,version,xcopy,fs)
+
+class rsakey_newfmt(rsakey):
+ "An old-style RSA public key in new-style sites format"
+ # This is its own class simply to have its own constructor.
+ def __init__(self,w):
+ self.a=w[1].name()
+ assert(self.a == 'rsa1')
+ self.d=w[2].base91()
+ try:
+ w_inner=list(map(Tainted,
+ ['X-PUB-RSA1'] +
+ base91s_decode(self.d)
+ .decode('ascii')
+ .split(' ')))
+ except UnicodeDecodeError:
+ complain('rsa1 key in new format has bad base91')
+ #print(repr(w_inner), file=sys.stderr)
+ rsakey.__init__(self,w_inner)
def somepubkey(w):
if w[0]=='pubkey':
return rsakey(w)
+ elif w[0]=='pub' and w[1]=='rsa1':
+ return rsakey_newfmt(w)
elif w[0]=='pub':
return pubkey(w)
else: