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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
use super::output_request::*;
use crate::base::*;
use crate::non::*;
use cyfs_base::*;

use std::fmt;

#[derive(Debug, Clone)]
pub struct CryptoInputRequestCommon {
    // 请求路径,可为空
    pub req_path: Option<String>,

    pub source: RequestSourceInfo,

    // 用以默认行为
    pub target: Option<ObjectId>,

    pub flags: u32,
}

impl fmt::Display for CryptoInputRequestCommon {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "req_path: {:?}", self.req_path)?;
        write!(f, ", {}", self.source)?;

        if let Some(target) = &self.target {
            write!(f, ", target: {}", target.to_string())?;
        }

        write!(f, ", flags: {}", self.flags)?;

        Ok(())
    }
}

#[derive(Debug, Clone)]
pub struct CryptoSignObjectInputRequest {
    pub common: CryptoInputRequestCommon,

    pub object: NONObjectInfo,

    pub flags: u32,
}

impl fmt::Display for CryptoSignObjectInputRequest {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "common: {}", self.common)?;
        write!(f, ", object: {}", self.object)?;

        write!(f, ", flags: {}", self.flags)
    }
}

pub type CryptoSignObjectInputResponse = CryptoSignObjectOutputResponse;

#[derive(Debug, Clone)]
pub struct CryptoVerifyObjectInputRequest {
    pub common: CryptoInputRequestCommon,

    // 校验的签名位置
    pub sign_type: VerifySignType,

    // 被校验对象
    pub object: NONObjectInfo,

    // 签名来源对象
    pub sign_object: VerifyObjectType,
}

impl fmt::Display for CryptoVerifyObjectInputRequest {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "common: {}", self.common)?;

        write!(f, ", object: {}", self.object)?;
        write!(f, ", sign_type: {:?}", self.sign_type)?;
        write!(f, ", sign_object: {:?}", self.sign_object)
    }
}

pub type CryptoVerifyObjectInputResponse = CryptoVerifyObjectOutputResponse;

#[derive(Debug, Clone)]
pub struct CryptoEncryptDataInputRequest {
    pub common: CryptoInputRequestCommon,

    pub encrypt_type: CryptoEncryptType,

    pub data: Option<Vec<u8>>,

    pub flags: u32,
}

impl CryptoEncryptDataInputRequest {
    pub fn data_len(&self) -> usize {
        match &self.data {
            Some(data) => data.len(),
            None => 0,
        }
    }
}

impl fmt::Display for CryptoEncryptDataInputRequest {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "common: {}", self.common)?;

        write!(f, ", encrypt_type: {}", self.encrypt_type.as_str())?;
        write!(
            f,
            ", data: {}",
            match &self.data {
                Some(data) => data.len(),
                None => 0,
            }
        )?;
        write!(f, ", flags: {}", self.flags)
    }
}

pub type CryptoEncryptDataInputResponse = CryptoEncryptDataOutputResponse;

#[derive(Debug, Clone)]
pub struct CryptoDecryptDataInputRequest {
    pub common: CryptoInputRequestCommon,

    pub decrypt_type: CryptoDecryptType,

    pub data: Vec<u8>,

    pub flags: u32,
}

impl fmt::Display for CryptoDecryptDataInputRequest {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        write!(f, "common: {}", self.common)?;

        write!(f, ", decrypt_type: {}", self.decrypt_type.as_str())?;
        write!(f, ", data: {}", self.data.len(),)?;
        write!(f, ", flags: {}", self.flags)
    }
}

pub type CryptoDecryptDataInputResponse = CryptoDecryptDataOutputResponse;