Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
Rust Openssl
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Public Repositories
Rust Openssl
Commits
c399c247
Commit
c399c247
authored
8 years ago
by
Jonas Schievink
Browse files
Options
Downloads
Patches
Plain Diff
Add RSA::private_key_from_pem_cb
parent
8119f06c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
openssl/src/crypto/rsa.rs
+22
-1
22 additions, 1 deletion
openssl/src/crypto/rsa.rs
with
22 additions
and
1 deletion
openssl/src/crypto/rsa.rs
+
22
−
1
View file @
c399c247
...
@@ -3,12 +3,13 @@ use std::fmt;
...
@@ -3,12 +3,13 @@ use std::fmt;
use
ssl
::
error
::{
SslError
,
StreamError
};
use
ssl
::
error
::{
SslError
,
StreamError
};
use
std
::
ptr
;
use
std
::
ptr
;
use
std
::
io
::{
self
,
Read
,
Write
};
use
std
::
io
::{
self
,
Read
,
Write
};
use
libc
::
c_int
;
use
libc
::
{
c_int
,
c_void
}
;
use
bn
::
BigNum
;
use
bn
::
BigNum
;
use
bio
::
MemBio
;
use
bio
::
MemBio
;
use
crypto
::
HashTypeInternals
;
use
crypto
::
HashTypeInternals
;
use
crypto
::
hash
;
use
crypto
::
hash
;
use
crypto
::
util
::{
CallbackState
,
invoke_passwd_cb
};
pub
struct
RSA
(
*
mut
ffi
::
RSA
);
pub
struct
RSA
(
*
mut
ffi
::
RSA
);
...
@@ -76,6 +77,26 @@ impl RSA {
...
@@ -76,6 +77,26 @@ impl RSA {
}
}
}
}
/// Reads an RSA private key from PEM formatted data and supplies a password callback.
pub
fn
private_key_from_pem_cb
<
R
,
F
>
(
reader
:
&
mut
R
,
pass_cb
:
F
)
->
Result
<
RSA
,
SslError
>
where
R
:
Read
,
F
:
FnMut
(
&
mut
[
i8
])
->
usize
{
let
mut
cb
=
CallbackState
::
new
(
pass_cb
);
let
mut
mem_bio
=
try
!
(
MemBio
::
new
());
try
!
(
io
::
copy
(
reader
,
&
mut
mem_bio
)
.map_err
(
StreamError
));
unsafe
{
let
cb_ptr
=
&
mut
cb
as
*
mut
_
as
*
mut
c_void
;
let
rsa
=
try_ssl_null!
(
ffi
::
PEM_read_bio_RSAPrivateKey
(
mem_bio
.get_handle
(),
ptr
::
null_mut
(),
Some
(
invoke_passwd_cb
::
<
F
>
),
cb_ptr
));
Ok
(
RSA
(
rsa
))
}
}
/// Writes an RSA private key as unencrypted PEM formatted data
/// Writes an RSA private key as unencrypted PEM formatted data
pub
fn
private_key_to_pem
<
W
>
(
&
self
,
writer
:
&
mut
W
)
->
Result
<
(),
SslError
>
pub
fn
private_key_to_pem
<
W
>
(
&
self
,
writer
:
&
mut
W
)
->
Result
<
(),
SslError
>
where
W
:
Write
where
W
:
Write
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment