示例#1
0
文件: SMIME.py 项目: rodrigc/m2crypto
 def sign(self, data_bio, flags=0):
     if not hasattr(self, 'pkey'):
         raise SMIME_Error('no private key: use load_key()')
     if hasattr(self, 'x509_stack'):
         pkcs7 = m2.pkcs7_sign1(self.x509._ptr(), self.pkey._ptr(),
                                self.x509_stack._ptr(),
                                data_bio._ptr(), flags)
         if pkcs7 is None:
             raise SMIME_Error(Err.get_error())
         return PKCS7(pkcs7, 1)
     else:
         pkcs7 = m2.pkcs7_sign0(self.x509._ptr(), self.pkey._ptr(),
                                data_bio._ptr(), flags)
         if pkcs7 is None:
             raise SMIME_Error(Err.get_error())
         return PKCS7(pkcs7, 1)
示例#2
0
 def sign(self, data_bio, flags=0):
     if not hasattr(self, 'pkey'):
         raise SMIME_Error('no private key: use load_key()')
     if hasattr(self, 'x509_stack'):
         pkcs7 = m2.pkcs7_sign1(self.x509._ptr(), self.pkey._ptr(),
                                self.x509_stack._ptr(), data_bio._ptr(),
                                flags)
         if pkcs7 is None:
             raise SMIME_Error(Err.get_error())
         return PKCS7(pkcs7, 1)
     else:
         pkcs7 = m2.pkcs7_sign0(self.x509._ptr(), self.pkey._ptr(),
                                data_bio._ptr(), flags)
         if pkcs7 is None:
             raise SMIME_Error(Err.get_error())
         return PKCS7(pkcs7, 1)
示例#3
0
    def sign(self, data_bio, flags=0, algo='sha1'):
        # type: (BIO.BIO, int, Optional[str]) -> PKCS7
        if not hasattr(self, 'pkey'):
            raise SMIME_Error('no private key: use load_key()')

        hash = getattr(m2, algo, None)

        if hash is None:
            raise SMIME_Error('no such hash algorithm %s' % algo)

        if hasattr(self, 'x509_stack'):
            pkcs7 = m2.pkcs7_sign1(self.x509._ptr(), self.pkey._ptr(),
                                   self.x509_stack._ptr(),
                                   data_bio._ptr(), hash(), flags)
            return PKCS7(pkcs7, 1)
        else:
            pkcs7 = m2.pkcs7_sign0(self.x509._ptr(), self.pkey._ptr(),
                                   data_bio._ptr(), hash(), flags)
            return PKCS7(pkcs7, 1)
示例#4
0
文件: SMIME.py 项目: mcepl/M2Crypto
    def sign(self, data_bio, flags=0, algo='sha1'):
        # type: (BIO.BIO, int, Optional[str]) -> PKCS7
        if not hasattr(self, 'pkey'):
            raise SMIME_Error('no private key: use load_key()')

        hash = getattr(m2, algo, None)

        if hash is None:
            raise SMIME_Error('no such hash algorithm %s' % algo)

        if hasattr(self, 'x509_stack'):
            pkcs7 = m2.pkcs7_sign1(self.x509._ptr(), self.pkey._ptr(),
                                   self.x509_stack._ptr(),
                                   data_bio._ptr(), hash(), flags)
            return PKCS7(pkcs7, 1)
        else:
            pkcs7 = m2.pkcs7_sign0(self.x509._ptr(), self.pkey._ptr(),
                                   data_bio._ptr(), hash(), flags)
            return PKCS7(pkcs7, 1)