/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() > to_usize(u16::MAX) { |
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 ReadArgs for Dsig { |
74 | | type Args = (); |
75 | | } |
76 | | |
77 | | impl<'a> FontRead<'a> for Dsig { |
78 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
79 | 0 | <read_fonts::tables::dsig::Dsig as FontRead>::read(data).map(|x| x.to_owned_table()) |
80 | 0 | } |
81 | | } |
82 | | |
83 | | impl FontWrite for PermissionFlags { |
84 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
85 | 0 | writer.write_slice(&self.bits().to_be_bytes()) |
86 | 0 | } |
87 | | } |
88 | | |
89 | | /// [Signature Record](https://learn.microsoft.com/en-us/typography/opentype/spec/dsig#table-structure) |
90 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
91 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
92 | | pub struct SignatureRecord { |
93 | | /// Offset to the signature block from the beginning of the table |
94 | | pub signature_block: OffsetMarker<SignatureBlockFormat1, WIDTH_32>, |
95 | | } |
96 | | |
97 | | impl SignatureRecord { |
98 | | /// Construct a new `SignatureRecord` |
99 | 0 | pub fn new(signature_block: SignatureBlockFormat1) -> Self { |
100 | 0 | Self { |
101 | 0 | signature_block: signature_block.into(), |
102 | 0 | } |
103 | 0 | } |
104 | | } |
105 | | |
106 | | impl FontWrite for SignatureRecord { |
107 | | #[allow(clippy::unnecessary_cast)] |
108 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
109 | 0 | (1 as u32).write_into(writer); |
110 | 0 | (self.compute_signature_block_len() as u32).write_into(writer); |
111 | 0 | self.signature_block.write_into(writer); |
112 | 0 | } |
113 | 0 | fn table_type(&self) -> TableType { |
114 | 0 | TableType::Named("SignatureRecord") |
115 | 0 | } |
116 | | } |
117 | | |
118 | | impl Validate for SignatureRecord { |
119 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
120 | 0 | ctx.in_table("SignatureRecord", |ctx| { |
121 | 0 | ctx.in_field("signature_block", |ctx| { |
122 | 0 | self.signature_block.validate_impl(ctx); |
123 | 0 | }); |
124 | 0 | }) |
125 | 0 | } |
126 | | } |
127 | | |
128 | | impl FromObjRef<read_fonts::tables::dsig::SignatureRecord> for SignatureRecord { |
129 | 0 | fn from_obj_ref( |
130 | 0 | obj: &read_fonts::tables::dsig::SignatureRecord, |
131 | 0 | offset_data: FontData, |
132 | 0 | ) -> Self { |
133 | 0 | SignatureRecord { |
134 | 0 | signature_block: obj.signature_block(offset_data).to_owned_table(), |
135 | 0 | } |
136 | 0 | } |
137 | | } |
138 | | |
139 | | /// [Signature Block Format 1](https://learn.microsoft.com/en-us/typography/opentype/spec/dsig#table-structure) |
140 | | #[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] |
141 | | #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] |
142 | | pub struct SignatureBlockFormat1 { |
143 | | /// PKCS#7 packet |
144 | | pub signature: Vec<u8>, |
145 | | } |
146 | | |
147 | | impl SignatureBlockFormat1 { |
148 | | /// Construct a new `SignatureBlockFormat1` |
149 | 0 | pub fn new(signature: Vec<u8>) -> Self { |
150 | 0 | Self { signature } |
151 | 0 | } |
152 | | } |
153 | | |
154 | | impl FontWrite for SignatureBlockFormat1 { |
155 | | #[allow(clippy::unnecessary_cast)] |
156 | 0 | fn write_into(&self, writer: &mut TableWriter) { |
157 | 0 | (0 as u16).write_into(writer); |
158 | 0 | (0 as u16).write_into(writer); |
159 | 0 | (u32::try_from(array_len(&self.signature)).unwrap()).write_into(writer); |
160 | 0 | self.signature.write_into(writer); |
161 | 0 | } |
162 | 0 | fn table_type(&self) -> TableType { |
163 | 0 | TableType::Named("SignatureBlockFormat1") |
164 | 0 | } |
165 | | } |
166 | | |
167 | | impl Validate for SignatureBlockFormat1 { |
168 | 0 | fn validate_impl(&self, ctx: &mut ValidationCtx) { |
169 | 0 | ctx.in_table("SignatureBlockFormat1", |ctx| { |
170 | 0 | ctx.in_field("signature", |ctx| { |
171 | 0 | if self.signature.len() > to_usize(u32::MAX) { |
172 | 0 | ctx.report("array exceeds max length"); |
173 | 0 | } |
174 | 0 | }); |
175 | 0 | }) |
176 | 0 | } |
177 | | } |
178 | | |
179 | | impl<'a> FromObjRef<read_fonts::tables::dsig::SignatureBlockFormat1<'a>> for SignatureBlockFormat1 { |
180 | 0 | fn from_obj_ref( |
181 | 0 | obj: &read_fonts::tables::dsig::SignatureBlockFormat1<'a>, |
182 | 0 | _: FontData, |
183 | 0 | ) -> Self { |
184 | 0 | let offset_data = obj.offset_data(); |
185 | 0 | SignatureBlockFormat1 { |
186 | 0 | signature: obj.signature().to_owned_obj(offset_data), |
187 | 0 | } |
188 | 0 | } |
189 | | } |
190 | | |
191 | | #[allow(clippy::needless_lifetimes)] |
192 | | impl<'a> FromTableRef<read_fonts::tables::dsig::SignatureBlockFormat1<'a>> |
193 | | for SignatureBlockFormat1 |
194 | | { |
195 | | } |
196 | | |
197 | | impl ReadArgs for SignatureBlockFormat1 { |
198 | | type Args = (); |
199 | | } |
200 | | |
201 | | impl<'a> FontRead<'a> for SignatureBlockFormat1 { |
202 | 0 | fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> { |
203 | 0 | <read_fonts::tables::dsig::SignatureBlockFormat1 as FontRead>::read(data) |
204 | 0 | .map(|x| x.to_owned_table()) |
205 | 0 | } |
206 | | } |