Skip to content

Commit d52be16

Browse files
authored
Merge pull request #1005 from samscott89/add-pkcs7-support
Add PKCS7 support
2 parents 3ee176e + 04ada47 commit d52be16

File tree

7 files changed

+474
-0
lines changed

7 files changed

+474
-0
lines changed

openssl-sys/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub use object::*;
2525
pub use ocsp::*;
2626
pub use ossl_typ::*;
2727
pub use pem::*;
28+
pub use pkcs7::*;
2829
pub use pkcs12::*;
2930
pub use rand::*;
3031
pub use rsa::*;
@@ -61,6 +62,7 @@ mod object;
6162
mod ocsp;
6263
mod ossl_typ;
6364
mod pem;
65+
mod pkcs7;
6466
mod pkcs12;
6567
mod rand;
6668
mod rsa;

openssl-sys/src/ossl_typ.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub enum ASN1_BIT_STRING {}
1010
pub enum ASN1_TIME {}
1111
pub enum ASN1_TYPE {}
1212
pub enum ASN1_OBJECT {}
13+
pub enum ASN1_OCTET_STRING {}
1314

1415
pub enum bio_st {} // FIXME remove
1516
cfg_if! {

openssl-sys/src/pem.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,15 @@ extern "C" {
132132
cb: pem_password_cb,
133133
u: *mut c_void,
134134
) -> *mut EVP_PKEY;
135+
136+
pub fn PEM_read_bio_PKCS7(
137+
bio: *mut BIO,
138+
out: *mut *mut PKCS7,
139+
cb: pem_password_cb,
140+
u: *mut c_void,
141+
) -> *mut PKCS7;
142+
143+
pub fn PEM_write_bio_PKCS7(bp: *mut BIO, x: *mut PKCS7) -> c_int;
135144
}
136145

137146
pub const PEM_R_NO_START_LINE: c_int = 108;

openssl-sys/src/pkcs7.rs

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
use libc::*;
2+
3+
use *;
4+
5+
pub enum PKCS7_SIGNED {}
6+
pub enum PKCS7_ENVELOPE {}
7+
pub enum PKCS7_SIGN_ENVELOPE {}
8+
pub enum PKCS7_DIGEST {}
9+
pub enum PKCS7_ENCRYPT {}
10+
pub enum PKCS7 {}
11+
12+
pub const PKCS7_TEXT: c_int = 0x1;
13+
pub const PKCS7_NOCERTS: c_int = 0x2;
14+
pub const PKCS7_NOSIGS: c_int = 0x4;
15+
pub const PKCS7_NOCHAIN: c_int = 0x8;
16+
pub const PKCS7_NOINTERN: c_int = 0x10;
17+
pub const PKCS7_NOVERIFY: c_int = 0x20;
18+
pub const PKCS7_DETACHED: c_int = 0x40;
19+
pub const PKCS7_BINARY: c_int = 0x80;
20+
pub const PKCS7_NOATTR: c_int = 0x100;
21+
pub const PKCS7_NOSMIMECAP: c_int = 0x200;
22+
pub const PKCS7_NOOLDMIMETYPE: c_int = 0x400;
23+
pub const PKCS7_CRLFEOL: c_int = 0x800;
24+
pub const PKCS7_STREAM: c_int = 0x1000;
25+
pub const PKCS7_NOCRL: c_int = 0x2000;
26+
pub const PKCS7_PARTIAL: c_int = 0x4000;
27+
pub const PKCS7_REUSE_DIGEST: c_int = 0x8000;
28+
#[cfg(not(any(ossl101, ossl102, libressl)))]
29+
pub const PKCS7_NO_DUAL_CONTENT: c_int = 0x10000;
30+
31+
extern "C" {
32+
pub fn PKCS7_encrypt(
33+
certs: *mut stack_st_X509,
34+
b: *mut BIO,
35+
cipher: *const EVP_CIPHER,
36+
flags: c_int,
37+
) -> *mut PKCS7;
38+
39+
pub fn PKCS7_verify(
40+
pkcs7: *mut PKCS7,
41+
certs: *mut stack_st_X509,
42+
store: *mut X509_STORE,
43+
indata: *mut BIO,
44+
out: *mut BIO,
45+
flags: c_int,
46+
) -> c_int;
47+
48+
pub fn PKCS7_sign(
49+
signcert: *mut X509,
50+
pkey: *mut EVP_PKEY,
51+
certs: *mut stack_st_X509,
52+
data: *mut BIO,
53+
flags: c_int,
54+
) -> *mut PKCS7;
55+
56+
pub fn PKCS7_decrypt(
57+
pkcs7: *mut PKCS7,
58+
pkey: *mut EVP_PKEY,
59+
cert: *mut X509,
60+
data: *mut BIO,
61+
flags: c_int,
62+
) -> c_int;
63+
64+
pub fn PKCS7_free(pkcs7: *mut PKCS7);
65+
66+
pub fn SMIME_write_PKCS7(
67+
out: *mut BIO,
68+
pkcs7: *mut PKCS7,
69+
data: *mut BIO,
70+
flags: c_int,
71+
) -> c_int;
72+
73+
pub fn SMIME_read_PKCS7(bio: *mut BIO, bcont: *mut *mut BIO) -> *mut PKCS7;
74+
}

openssl/src/bio.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ impl MemBio {
6666
slice::from_raw_parts(ptr as *const _ as *const _, len as usize)
6767
}
6868
}
69+
70+
pub unsafe fn from_ptr(bio: *mut ffi::BIO) -> MemBio {
71+
MemBio(bio)
72+
}
6973
}
7074

7175
cfg_if! {

openssl/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ pub mod nid;
161161
pub mod ocsp;
162162
pub mod pkcs12;
163163
pub mod pkcs5;
164+
pub mod pkcs7;
164165
pub mod pkey;
165166
pub mod rand;
166167
pub mod rsa;

0 commit comments

Comments
 (0)