def ensureEncProperties(self, id=None): ep = self.find(enc("EncryptionProperties")) if ep is None: ep = mkse(self, enc("EncryptionProperties"), attrib=id and dict(Id=id) or None, ) return ep
def addKeyReference(self, uri=None): rl = self.find(enc("ReferenceList")) if rl is None: rl = mke(enc("ReferenceList")) self.insert(0, rl) return mkse(rl, enc("KeyReference"), attrib=uri and dict(URI=uri) or None)
def addKeyReference(self, uri=None): rl = self.find(enc("ReferenceList")) if rl is None: rl = mke(self, enc("ReferenceList")) self.insert(0, rl) return mkse(rl, enc("KeyReference"), attrib=uri and dict(URI=uri) or None )
def ensureCipherReference(self, uri=None): cd = self.find(enc("CipherData")) cr = cd.find(enc("CipherReference")) if cr is None: if len(cd): raise ValueError("`CipherData` can only contain a single element") cr = mkse(cd, enc("CipherReference"), attrib=uri and dict(URI=uri) or None) return cr
def ensureCipherValue(self): cd = self.find(enc("CipherData")) cv = cd.find(enc("CipherValue")) if cv is None: if len(cd): raise ValueError("`CipherData` can only contain a single element") cv = mkse(cd, enc("CipherValue")) return cv
def ensureCipherValue(self): cd = self.find(enc("CipherData")) cv = cd.find(enc("CipherValue")) if cv is None: if len(cd): raise ValueError( "`CipherData` can only contain a single element") cv = mkse(cd, enc("CipherValue")) return cv
def ensureEncProperties(self, id=None): ep = self.find(enc("EncryptionProperties")) if ep is None: ep = mkse( self, enc("EncryptionProperties"), attrib=id and dict(Id=id) or None, ) return ep
def ensureCipherReference(self, uri=None): cd = self.find(enc("CipherData")) cr = cd.find(enc("CipherReference")) if cr is None: if len(cd): raise ValueError( "`CipherData` can only contain a single element") cr = mkse(cd, enc("CipherReference"), attrib=uri and dict(URI=uri) or None) return cr
def _EncType_(tag, encMethod=None, id=None, type=None, mimeType=None, encoding=None, recipient=None, nsPrefix=None): attrib = {} if id: attrib["Id"] = id if type: attrib["Type"] = type if mimeType: attrib["MimeType"] = mimeTpye if encoding: attrib["Encoding"] = encoding if recipient: attrib["Recipient"] = recipient nsmap = nsPrefix and dict(nsPrefix=EncNs) or EncNsMap et = mke(enc(tag), attrib=attrib, nsmap=nsmap) if encMethod: mkse(et, enc("EncryptionMethod"), Algorithm=encMethod.href) mkse(et, enc("CipherData")) return et
def addEncProperty(self, id=None, target=None): attrib = {} if id: attrib["Id"] = id if target: attrib["Target"] = target return mkse(self.ensureEncProperties(), enc("EncryptionProperty"), attrib=attrib)
def ensureKeyInfo(self, id=None): ki = self.find(dsig("KeyInfo")) if ki is None: ki = mke(dsig("KeyInfo"), attrib=id and dict(Id=id) or None) kii = self.find(enc("EncryptionMethod")) is not None and 1 or 0 self.insert(kii, ki) return ki
def ensureKeyInfo(self, id=None): ki = self.find(dsig("KeyInfo")) if ki is None: ki = mke( dsig("KeyInfo"), attrib=id and dict(Id=id) or None, ) kii = self.find(enc("EncryptionMethod")) is not None and 1 or 0 self.insert(kii, ki) return ki
def _EncType_(tag, encMethod=None, id=None, type=None, mimeType=None, encoding=None, recipient=None, nsPrefix=None): attrib = {} if id: attrib["Id"] = id if type: attrib["Type"] = type if mimeType: attrib["MimeType"] = mimeTpye if encoding: attrib["Encoding"] = encoding if recipient: attrib["Recipient"] = recipient nsmap = nsPrefix and {nsPrefix: EncNs} or EncNsMap et = mke(enc(tag), attrib=attrib, nsmap=nsmap) if encMethod: mkse(et, enc("EncryptionMethod"), Algorithm=encMethod.href) mkse(et, enc("CipherData")) return et
def addTransform(self, transform): ts = self.find(enc("Transforms")) if ts is None: ts = mkse(self, enc("Transforms")) t = mkse(ts, dsig("Transform"), Algorithm=transform.href) return t
def addOAEPparams(self, params): # may need to control position return mkse(self, enc("OAEPParams"), params.encode("base64"))