Encoding: Refactor export
This commit is contained in:
parent
e69cd8c2a7
commit
c08ad88303
|
@ -11,8 +11,7 @@ fn main() {
|
|||
let key2 = fb.add(msg2.as_bytes());
|
||||
|
||||
// Export as base64
|
||||
let cipher = fb.export_cipher();
|
||||
let keybase = fb.export_keybase();
|
||||
let (cipher, keybase) = fb.export(); // Careful with the order
|
||||
let key1_exp = key1.export();
|
||||
// Or as raw bytes
|
||||
let key2_exp = key2.to_bytes();
|
||||
|
|
|
@ -7,24 +7,21 @@ where
|
|||
Self: FBObjTrait<T>,
|
||||
T: ArrayEncoding + Bounded,
|
||||
{
|
||||
fn to_bytes_cipher(&self) -> Vec<u8> {
|
||||
self.cipher().iter()
|
||||
fn to_bytes(&self) -> (Vec<u8>, Vec<u8>) {
|
||||
let c = self.cipher().iter()
|
||||
.flat_map(|bigint| bigint.to_le_byte_array())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn to_bytes_keybase(&self) -> Vec<u8> {
|
||||
self.keybase().iter()
|
||||
.collect();
|
||||
let r = self.keybase().iter()
|
||||
.flat_map(|bigint| bigint.to_le_byte_array())
|
||||
.collect()
|
||||
.collect();
|
||||
|
||||
(c, r)
|
||||
}
|
||||
|
||||
fn export_cipher(&self) -> String {
|
||||
BASE64_STANDARD.encode(self.to_bytes_cipher())
|
||||
}
|
||||
fn export(&self) -> (String, String) {
|
||||
let (c, r) = self.to_bytes();
|
||||
|
||||
fn export_keybase(&self) -> String {
|
||||
BASE64_STANDARD.encode(self.to_bytes_keybase())
|
||||
(BASE64_STANDARD.encode(c), BASE64_STANDARD.encode(r))
|
||||
}
|
||||
|
||||
fn from_bytes(cipher: &[u8], keybase: &[u8]) -> Result<FBObj<T>, FBError> {
|
||||
|
|
Loading…
Reference in New Issue