+ # 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)
+
+class pubkey_group(basetype):
+ "Public key group introducer"
+ # appears in the site's list of keys mixed in with the keys
+ def __init__(self,w,fallback):
+ self.i=w[1].hexid(4,'pkg-id')
+ self.fallback=fallback
+ def forsites(self,version,xcopy,fs):
+ fs.pkg=self.i
+ if version < 2: return []
+ return ['pkgf' if self.fallback else 'pkg', self.i]
+
+def somepubkey(w):
+ #print(repr(w), file=sys.stderr)
+ 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)
+ elif w[0]=='pkg':
+ return pubkey_group(w,False)
+ elif w[0]=='pkgf':
+ return pubkey_group(w,True)
+ else:
+ assert(False)