1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use itertools::Itertools;
use crate::structs::{Address, ErrorCode as RGError, ErrorInfo, Proof};
use crate::proto_serde::ProtoSerde;
use crate::{error_message, structs, HashClear, RgResult, SafeOption};
impl HashClear for Proof {
// TODO: Separate the hashclear method for those that don't require clears
fn hash_clear(&mut self) {}
}
impl Proof {
pub fn signature_hex(&self) -> RgResult<String> {
Ok(hex::encode(self.signature_bytes()?))
}
// pub fn public_key_bytes(&self) -> Result<Vec<u8>, ErrorInfo> {
// // Ok(self.public_key.safe_get_msg("Missing public key")?.bytes()?)
// Ok(self
// .public_key
// .as_ref()
// .ok_or(error_message(RGError::MissingField, "public_key"))?
// .clone()
// .bytes
// .as_ref()
// .ok_or(error_message(
// RGError::MissingField,
// "public_key bytes data",
// ))?
// .value
// .clone())
// }
pub fn public_key_direct_bytes(&self) -> Result<Vec<u8>, ErrorInfo> {
// Ok(self.public_key.safe_get_msg("Missing public key")?.bytes()?)
Ok(self
.public_key
.as_ref()
.ok_or(error_message(RGError::MissingField, "public_key"))?
.clone()
.bytes
.as_ref()
.ok_or(error_message(
RGError::MissingField,
"public_key bytes data",
))?
.value
.clone())
}
pub fn public_key_proto_bytes(&self) -> Result<Vec<u8>, ErrorInfo> {
Ok(self.public_key.safe_get_msg("Missing public key")?.vec())
}
pub fn signature_bytes(&self) -> Result<Vec<u8>, ErrorInfo> {
Ok(self
.signature
.as_ref()
.ok_or(error_message(RGError::MissingField, "signature"))?
.clone()
.bytes
.as_ref()
.ok_or(error_message(RGError::MissingField, "signature bytes data"))?
.value
.clone())
}
pub fn from(public_key: structs::PublicKey, signature: structs::Signature) -> Self {
Self {
signature: Some(signature),
public_key: Some(public_key),
}
}
}