Skip to content

Commit

Permalink
feat(ffi): implement skey_from_bytes
Browse files Browse the repository at this point in the history
Former-commit-id: 9889aee
  • Loading branch information
dignifiedquire committed Mar 2, 2019
1 parent 6674760 commit 460efdd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pgp-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use std::os::raw::c_char;
use std::slice::from_raw_parts;

use pgp::composed::{
from_armor_many, from_bytes_many, KeyType, PublicOrSecret, SecretKeyParamsBuilder,
SignedPublicKey, SignedSecretKey, SubkeyParamsBuilder,
from_armor_many, from_bytes_many, Deserializable, KeyType, PublicOrSecret,
SecretKeyParamsBuilder, SignedPublicKey, SignedSecretKey, SubkeyParamsBuilder,
};
use pgp::crypto::{HashAlgorithm, SymmetricKeyAlgorithm};
use pgp::errors::Result;
Expand Down Expand Up @@ -91,6 +91,18 @@ pub unsafe extern "C" fn rpgp_skey_drop(skey_ptr: *mut signed_secret_key) {
// Drop
}

/// Creates an in-memory representation of a Secret PGP key, based on the serialized bytes given.
#[no_mangle]
pub unsafe extern "C" fn rpgp_skey_from_bytes(
raw: *const u8,
len: libc::size_t,
) -> *mut signed_secret_key {
let bytes = from_raw_parts(raw, len);
let key = SignedSecretKey::from_bytes(Cursor::new(bytes)).expect("invalid secret key");

Box::into_raw(Box::new(key))
}

#[no_mangle]
pub unsafe extern "C" fn rpgp_pkey_to_bytes(pkey_ptr: *mut signed_public_key) -> *mut cvec {
let pkey = &*pkey_ptr;
Expand Down

0 comments on commit 460efdd

Please sign in to comment.