Skip to content

Commit 54f7523

Browse files
committed
added clone methods to record_ciphertext and record_plaintext modules
1 parent f4bc391 commit 54f7523

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

wasm/src/record/record_ciphertext.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ impl RecordCiphertext {
156156
pub fn nonce(&self) -> Group {
157157
Group::from(self.0.nonce())
158158
}
159+
160+
/// Clone the record ciphertext.
161+
///
162+
/// @returns {RecordCiphertext} A clone of the record ciphertext.
163+
/// Clone the field element.
164+
#[allow(clippy::should_implement_trait)]
165+
pub fn clone(&self) -> RecordCiphertext {
166+
RecordCiphertext(self.0.clone())
167+
}
159168
}
160169

161170
impl Deref for RecordCiphertext {
@@ -235,6 +244,13 @@ mod tests {
235244
assert!(RecordCiphertext::from_string(invalid_bech32).is_err());
236245
}
237246

247+
#[wasm_bindgen_test]
248+
fn test_clone() {
249+
let record = RecordCiphertext::from_string(OWNER_CIPHERTEXT).unwrap();
250+
let cloned_record = record.clone();
251+
assert_eq!(record.to_string(), cloned_record.to_string());
252+
}
253+
238254
#[wasm_bindgen_test]
239255
fn test_decrypt_and_tag_computation() {
240256
let record = RecordCiphertext::from_string(OWNER_CIPHERTEXT).unwrap();

wasm/src/record/record_plaintext.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,15 @@ impl RecordPlaintext {
265265
pub fn record_view_key(&self, view_key: &ViewKey) -> Field {
266266
Group::from_string(&self.nonce()).unwrap().scalar_multiply(&view_key.to_scalar()).to_x_coordinate()
267267
}
268+
269+
/// Clone the record plaintext.
270+
///
271+
/// @returns {RecordPlaintext} A clone of the record plaintext.
272+
/// Clone the field element.
273+
#[allow(clippy::should_implement_trait)]
274+
pub fn clone(&self) -> RecordPlaintext {
275+
RecordPlaintext(self.0.clone())
276+
}
268277
}
269278

270279
impl Deref for RecordPlaintext {
@@ -341,6 +350,13 @@ mod tests {
341350
assert_eq!(record.to_string(), CREDITS_RECORD);
342351
}
343352

353+
#[wasm_bindgen_test]
354+
fn test_clone() {
355+
let record = RecordPlaintext::from_string(CREDITS_RECORD).unwrap();
356+
let cloned_record = record.clone();
357+
assert_eq!(record.to_string(), cloned_record.to_string());
358+
}
359+
344360
#[wasm_bindgen_test]
345361
fn test_get_record_member() {
346362
// Get the record members.

0 commit comments

Comments
 (0)