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