catbuffer_rust/
proof_scalar_dto.rs

1/*
2 * // Copyright (c) 2016-2019, Jaguar0625, gimre, BloodyRookie, Tech Bureau, Corp.
3 * // Copyright (c) 2020-present, Jaguar0625, gimre, BloodyRookie.
4 * // All rights reserved.
5 * //
6 * // This file is part of Catapult.
7 * //
8 * // Catapult is free software: you can redistribute it and/or modify
9 * // it under the terms of the GNU Lesser General Public License as published by
10 * // the Free Software Foundation, either version 3 of the License, or
11 * // (at your option) any later version.
12 * //
13 * // Catapult is distributed in the hope that it will be useful,
14 * // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * // GNU Lesser General Public License for more details.
17 * //
18 * // You should have received a copy of the GNU Lesser General Public License
19 * // along with Catapult. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22use super::generator_utils::*;
23
24/// Proof scalar.
25#[derive(Debug, Clone, Copy)]
26pub struct ProofScalarDto(pub [u8; 32]);
27
28impl ProofScalarDto {
29    pub const LENGTH: usize = std::mem::size_of::<Self>();
30
31    /// Gets the size of the type.
32    ///
33    /// # Returns
34    /// A usize.
35    pub fn get_size(&self) -> usize {
36        Self::LENGTH
37    }
38
39    /// Gets Proof scalar.
40    ///
41    /// # Returns
42    /// A Proof scalar.
43    pub fn get_proof_scalar(&self) -> [u8; 32] {
44        self.0
45    }
46
47    /// Serializes an type to bytes.
48    ///
49    /// # Returns
50    /// A Serialized bytes.
51    pub fn serializer(&self) -> Vec<u8> {
52        let mut buffer = Vec::with_capacity(self.get_size());
53        buffer.extend(self.0.to_vec());
54        buffer
55    }
56
57    /// Creates an `ProofScalarDto` from a slice.
58    ///
59    /// # Returns
60    /// A `ProofScalarDto`.
61    pub fn from_binary(src: &[u8]) -> Self {
62        // assert_eq!(src.len(), Self::LENGTH);
63        let buf = fixed_bytes::<{ Self::LENGTH }>(src);
64        Self(buf)
65    }
66}