+ bad_base91=re.compile(r'[^!-~]|[\'\"\\]')
+ def base91(self,what='base91'):
+ ok=self._re_ok(Tainted.bad_base91,what,4096)
+ return self._rtn(ok)
+
+class ArgActionLambda(argparse.Action):
+ def __init__(self, fn, **kwargs):
+ self.fn=fn
+ argparse.Action.__init__(self,**kwargs)
+ def __call__(self,ap,ns,values,option_string):
+ self.fn(values,ns,ap,option_string)
+
+class PkmBase():
+ def site_start(self,pubkeys_path):
+ self._pa=pubkeys_path
+ self._fs = FilterState()
+ def site_serial(self,serial): pass
+ def write_key(self,k): pass
+ def site_finish(self,confw): pass
+
+class PkmSingle(PkmBase):
+ opt = 'single'
+ help = 'write one public key per site to sites.conf'
+ def site_start(self,pubkeys_path):
+ PkmBase.site_start(self,pubkeys_path)
+ self._outk = []
+ def write_key(self,k):
+ if k.okforonlykey(output_version,self._fs):
+ self._outk.append(k)
+ def site_finish(self,confw):
+ if len(self._outk) == 0:
+ complain("site with no public key");
+ elif len(self._outk) != 1:
+ debugrepr('outk ', self._outk)
+ complain(
+ "site with multiple public keys, without --pubkeys-install (maybe --output-version=1 would help"
+ )
+ else:
+ confw.write("key %s;\n"%str(self._outk[0]))
+
+class PkmInstall(PkmBase):
+ opt = 'install'
+ help = 'install public keys in public key directory'
+ def site_start(self,pubkeys_path):
+ PkmBase.site_start(self,pubkeys_path)
+ self._pw=open(self._pa+'~tmp','w')
+ def site_serial(self,serial):
+ self._pw.write('serial %s\n' % serial)
+ def write_key(self,k):
+ wout=k.forpub(output_version,self._fs)
+ self._pw.write(' '.join(wout))
+ self._pw.write('\n')
+ def site_finish(self,confw):
+ self._pw.close()
+ os.rename(self._pa+'~tmp',self._pa+'~update')
+ PkmElide.site_finish(self,confw)
+
+class PkmElide(PkmBase):
+ opt = 'elide'
+ help = 'no public keys in sites.conf output nor in directory'
+ def site_finish(self,confw):
+ confw.write("peer-keys \"%s\";\n"%self._pa);
+