~ubuntu-branches/ubuntu/saucy/m2crypto/saucy

« back to all changes in this revision

Viewing changes to M2Crypto/SMIME.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2009-11-06 01:28:39 UTC
  • mfrom: (2.2.5 sid)
  • Revision ID: james.westby@ubuntu.com-20091106012839-zjjugwmj8zggokqh
Tags: 0.20.1-1ubuntu1
* Merge from debian testing, remaining changes:
  - debian/rules; enable testsuite, add more files to "clean" rule.
  - tests/test_ssl.py: use signal 9 to kill old s_server processes
    to work around build HUP signal-ignore-mask (LP: #451998).

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
def load_pkcs7(p7file):
64
64
    bio = m2.bio_new_file(p7file, 'r')
65
65
    if bio is None:
66
 
        raise Err.get_error()
 
66
        raise BIO.BIOError(Err.get_error())
67
67
 
68
68
    try:
69
69
        p7_ptr = m2.pkcs7_read_bio(bio)
71
71
        m2.bio_free(bio)
72
72
        
73
73
    if p7_ptr is None:
74
 
        raise Err.get_error()
 
74
        raise PKCS7_Error(Err.get_error())
75
75
    return PKCS7(p7_ptr, 1)
76
76
    
77
77
 
78
78
def load_pkcs7_bio(p7_bio):
79
79
    p7_ptr = m2.pkcs7_read_bio(p7_bio._ptr())
80
80
    if p7_ptr is None:
81
 
        raise Err.get_error()
 
81
        raise PKCS7_Error(Err.get_error())
82
82
    return PKCS7(p7_ptr, 1)
83
83
    
84
84
 
85
85
def smime_load_pkcs7(p7file):
86
86
    bio = m2.bio_new_file(p7file, 'r')
87
87
    if bio is None:
88
 
        raise Err.get_error()
 
88
        raise BIO.BIOError(Err.get_error())
89
89
    
90
90
    try:
91
91
        p7_ptr, bio_ptr = m2.smime_read_pkcs7(bio)
93
93
        m2.bio_free(bio)
94
94
    
95
95
    if p7_ptr is None:
96
 
        raise Err.get_error()
 
96
        raise SMIME_Error(Err.get_error())
97
97
    if bio_ptr is None:
98
98
        return PKCS7(p7_ptr, 1), None
99
99
    else:
103
103
def smime_load_pkcs7_bio(p7_bio):
104
104
    p7_ptr, bio_ptr = m2.smime_read_pkcs7(p7_bio._ptr())
105
105
    if p7_ptr is None:
106
 
        raise Err.get_error()
 
106
        raise SMIME_Error(Err.get_error())
107
107
    if bio_ptr is None:
108
108
        return PKCS7(p7_ptr, 1), None
109
109
    else:
175
175
            raise SMIME_Error, 'no recipient certs: use set_x509_stack()'
176
176
        pkcs7 = m2.pkcs7_encrypt(self.x509_stack._ptr(), data_bio._ptr(), self.cipher._ptr(), flags)
177
177
        if pkcs7 is None:
178
 
            raise SMIME_Error, Err.get_error()
 
178
            raise SMIME_Error(Err.get_error())
179
179
        return PKCS7(pkcs7, 1)
180
180
 
181
181
    def decrypt(self, pkcs7, flags=0):
185
185
            raise SMIME_Error, 'no certificate: load_key() used incorrectly?'
186
186
        blob = m2.pkcs7_decrypt(pkcs7._ptr(), self.pkey._ptr(), self.x509._ptr(), flags)
187
187
        if blob is None:
188
 
            raise SMIME_Error, Err.get_error()
 
188
            raise SMIME_Error(Err.get_error())
189
189
        return blob
190
190
 
191
191
    def sign(self, data_bio, flags=0):
195
195
            pkcs7 = m2.pkcs7_sign1(self.x509._ptr(), self.pkey._ptr(), 
196
196
                self.x509_stack._ptr(), data_bio._ptr(), flags)
197
197
            if pkcs7 is None:
198
 
                raise SMIME_Error, Err.get_error()
 
198
                raise SMIME_Error(Err.get_error())
199
199
            return PKCS7(pkcs7, 1)
200
200
        else:
201
201
            pkcs7 = m2.pkcs7_sign0(self.x509._ptr(), self.pkey._ptr(), 
202
202
                data_bio._ptr(), flags)
203
203
            if pkcs7 is None:
204
 
                raise SMIME_Error, Err.get_error()
 
204
                raise SMIME_Error(Err.get_error())
205
205
            return PKCS7(pkcs7, 1)
206
206
 
207
207
    def verify(self, pkcs7, data_bio=None, flags=0):
216
216
        else:
217
217
            blob = m2.pkcs7_verify1(p7, self.x509_stack._ptr(), self.x509_store._ptr(), data_bio._ptr(), flags)
218
218
        if blob is None:
219
 
            raise SMIME_Error, Err.get_error()
 
219
            raise SMIME_Error(Err.get_error())
220
220
        return blob
221
221
 
222
222
    def write(self, out_bio, pkcs7, data_bio=None, flags=0):
230
230
def text_crlf(text):
231
231
    bio_in = BIO.MemoryBuffer(text)
232
232
    bio_out = BIO.MemoryBuffer()
233
 
    if m2.smime_crlf_copy(bio_in, bio_out):
 
233
    if m2.smime_crlf_copy(bio_in._ptr(), bio_out._ptr()):
234
234
        return bio_out.read()
235
235
    else:
236
 
        raise Err.get_error()
 
236
        raise SMIME_Error(Err.get_error())
237
237
 
238
238
 
239
239
def text_crlf_bio(bio_in):
240
240
    bio_out = BIO.MemoryBuffer()
241
 
    m2.smime_crlf_copy(bio_in, bio_out)
242
 
    if m2.smime_crlf_copy(bio_in, bio_out):
 
241
    if m2.smime_crlf_copy(bio_in._ptr(), bio_out._ptr()):
243
242
        return bio_out
244
243
    else:
245
 
        raise Err.get_error()
 
244
        raise SMIME_Error(Err.get_error())
246
245