/src/fontations/write-fonts/generated/generated_dsig.rs
Line | Count | Source |
1 | | // THIS FILE IS AUTOGENERATED. |
2 | | // Any changes to this file will be overwritten. |
3 | | // For more information about how codegen works, see font-codegen/README.md |
4 | | |
5 | | #[allow(unused_imports)] |
6 | | use crate::codegen_prelude::*; |
7 | | |
8 | | pub use read_fonts::tables::dsig::PermissionFlags; |
9 | | |
10 | | /// [DSIG (Digital Signature Table)](https://docs.microsoft.com/en-us/typography/opentype/spec/dsig#table-structure) table |
11 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
12 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
13 | | pub struct Dsig { |
14 | | /// Permission flags |
15 | | pub flags: PermissionFlags, |
16 | | /// Array of signature records |
17 | | pub signature_records: Vec<SignatureRecord>, |
18 | | } |
19 | | |
20 | | impl Dsig { |
21 | | /// Construct a new `Dsig` |
22 | 0 | pub fn new(flags: PermissionFlags, signature_records: Vec<SignatureRecord>) -> Self { |
23 | 0 | Self { |
24 | 0 | flags, |
25 | 0 | signature_records, |
26 | 0 | } |
27 | 0 | } |
28 | | } |
29 | | |
30 | | impl FontWrite for Dsig { |
31 | | #[allow(clippy::unnecessary_cast)] |
32 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
33 | 0 | (1 as u32).write_into(writer); |
34 | 0 | (u16::try_from(array_len(&self.signature_records)).unwrap()).write_into(writer); |
35 | 0 | self.flags.write_into(writer); |
36 | 0 | self.signature_records.write_into(writer); |
37 | 0 | } |
38 | 0 | fn table_type(&self) -> TableType { |
39 | 0 | TableType::TopLevel(Dsig::TAG) |
40 | 0 | } |
41 | | } |
42 | | |
43 | | impl Validate for Dsig { |
44 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
45 | 0 | ctx.in_table("Dsig", |ctx| { |
46 | 0 | ctx.in_field("signature_records", |ctx| { |
47 | 0 | if self.signature_records.len() > (u16::MAX as usize) { |
48 | 0 | ctx.report("array exceeds max length"); |
49 | 0 | } |
50 | 0 | self.signature_records.validate_impl(ctx); |
51 | 0 | }); |
52 | 0 | }) |
53 | 0 | } |
54 | | } |
55 | | |
56 | | impl TopLevelTable for Dsig { |
57 | | const TAG: Tag = Tag::new(b"DSIG"); |
58 | | } |
59 | | |
60 | | impl<'a> FromObjRef<read_fonts::tables::dsig::Dsig<'a>> for Dsig { |
61 | 0 | fn from_obj_ref(obj: &read_fonts::tables::dsig::Dsig<'a>, _: FontData) -> Self { |
62 | 0 | let offset_data = obj.offset_data(); |
63 | 0 | Dsig { |
64 | 0 | flags: obj.flags(), |
65 | 0 | signature_records: obj.signature_records().to_owned_obj(offset_data), |
66 | 0 | } |
67 | 0 | } |
68 | | } |
69 | | |
70 | | #[allow(clippy::needless_lifetimes)] |
71 | | impl<'a> FromTableRef<read_fonts::tables::dsig::Dsig<'a>> for Dsig {} |
72 | | |
73 | | impl<'a> FontRead<'a> for Dsig { |
74 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
75 | 0 | <read_fonts::tables::dsig::Dsig as FontRead>::read(data).map(|x| x.to_owned_table()) |
76 | 0 | } |
77 | | } |
78 | | |
79 | | impl FontWrite for PermissionFlags { |
80 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
81 | 0 | writer.write_slice(&self.bits().to_be_bytes()) |
82 | 0 | } |
83 | | } |
84 | | |
85 | | /// [Signature Record](https://learn.microsoft.com/en-us/typography/opentype/spec/dsig#table-structure) |
86 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
87 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
88 | | pub struct SignatureRecord { |
89 | | /// Offset to the signature block from the beginning of the table |
90 | | pub signature_block: OffsetMarker<SignatureBlockFormat1, WIDTH_32>, |
91 | | } |
92 | | |
93 | | impl SignatureRecord { |
94 | | /// Construct a new `SignatureRecord` |
95 | 0 | pub fn new(signature_block: SignatureBlockFormat1) -> Self { |
96 | 0 | Self { |
97 | 0 | signature_block: signature_block.into(), |
98 | 0 | } |
99 | 0 | } |
100 | | } |
101 | | |
102 | | impl FontWrite for SignatureRecord { |
103 | | #[allow(clippy::unnecessary_cast)] |
104 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
105 | 0 | (1 as u32).write_into(writer); |
106 | 0 | (self.compute_signature_block_len() as u32).write_into(writer); |
107 | 0 | self.signature_block.write_into(writer); |
108 | 0 | } |
109 | 0 | fn table_type(&self) -> TableType { |
110 | 0 | TableType::Named("SignatureRecord") |
111 | 0 | } |
112 | | } |
113 | | |
114 | | impl Validate for SignatureRecord { |
115 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
116 | 0 | ctx.in_table("SignatureRecord", |ctx| { |
117 | 0 | ctx.in_field("signature_block", |ctx| { |
118 | 0 | self.signature_block.validate_impl(ctx); |
119 | 0 | }); |
120 | 0 | }) |
121 | 0 | } |
122 | | } |
123 | | |
124 | | impl FromObjRef<read_fonts::tables::dsig::SignatureRecord> for SignatureRecord { |
125 | 0 | fn from_obj_ref( |
126 | 0 | obj: &read_fonts::tables::dsig::SignatureRecord, |
127 | 0 | offset_data: FontData, |
128 | 0 | ) -> Self { |
129 | 0 | SignatureRecord { |
130 | 0 | signature_block: obj.signature_block(offset_data).to_owned_table(), |
131 | 0 | } |
132 | 0 | } |
133 | | } |
134 | | |
135 | | /// [Signature Block Format 1](https://learn.microsoft.com/en-us/typography/opentype/spec/dsig#table-structure) |
136 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
137 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
138 | | pub struct SignatureBlockFormat1 { |
139 | | /// PKCS#7 packet |
140 | | pub signature: Vec<u8>, |
141 | | } |
142 | | |
143 | | impl SignatureBlockFormat1 { |
144 | | /// Construct a new `SignatureBlockFormat1` |
145 | 0 | pub fn new(signature: Vec<u8>) -> Self { |
146 | 0 | Self { signature } |
147 | 0 | } |
148 | | } |
149 | | |
150 | | impl FontWrite for SignatureBlockFormat1 { |
151 | | #[allow(clippy::unnecessary_cast)] |
152 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
153 | 0 | (0 as u16).write_into(writer); |
154 | 0 | (0 as u16).write_into(writer); |
155 | 0 | (u32::try_from(array_len(&self.signature)).unwrap()).write_into(writer); |
156 | 0 | self.signature.write_into(writer); |
157 | 0 | } |
158 | 0 | fn table_type(&self) -> TableType { |
159 | 0 | TableType::Named("SignatureBlockFormat1") |
160 | 0 | } |
161 | | } |
162 | | |
163 | | impl Validate for SignatureBlockFormat1 { |
164 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
165 | 0 | ctx.in_table("SignatureBlockFormat1", |ctx| { |
166 | 0 | ctx.in_field("signature", |ctx| { |
167 | 0 | if self.signature.len() > (u32::MAX as usize) { |
168 | 0 | ctx.report("array exceeds max length"); |
169 | 0 | } |
170 | 0 | }); |
171 | 0 | }) |
172 | 0 | } |
173 | | } |
174 | | |
175 | | impl<'a> FromObjRef<read_fonts::tables::dsig::SignatureBlockFormat1<'a>> for SignatureBlockFormat1 { |
176 | 0 | fn from_obj_ref( |
177 | 0 | obj: &read_fonts::tables::dsig::SignatureBlockFormat1<'a>, |
178 | 0 | _: FontData, |
179 | 0 | ) -> Self { |
180 | 0 | let offset_data = obj.offset_data(); |
181 | 0 | SignatureBlockFormat1 { |
182 | 0 | signature: obj.signature().to_owned_obj(offset_data), |
183 | 0 | } |
184 | 0 | } |
185 | | } |
186 | | |
187 | | #[allow(clippy::needless_lifetimes)] |
188 | | impl<'a> FromTableRef<read_fonts::tables::dsig::SignatureBlockFormat1<'a>> |
189 | | for SignatureBlockFormat1 |
190 | | { |
191 | | } |
192 | | |
193 | | impl<'a> FontRead<'a> for SignatureBlockFormat1 { |
194 | 0 | fn read(data: FontData<'a>) -> Result<Self, ReadError> { |
195 | 0 | <read_fonts::tables::dsig::SignatureBlockFormat1 as FontRead>::read(data) |
196 | 0 | .map(|x| x.to_owned_table()) |
197 | 0 | } |
198 | | } |