Skip to main content

write_fonts/generated/
generated_dsig.rs

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)]
6use crate::codegen_prelude::*;
7
8pub 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))]
13pub struct Dsig {
14    /// Permission flags
15    pub flags: PermissionFlags,
16    /// Array of signature records
17    pub signature_records: Vec<SignatureRecord>,
18}
19
20impl Dsig {
21    /// Construct a new `Dsig`
22    pub fn new(flags: PermissionFlags, signature_records: Vec<SignatureRecord>) -> Self {
23        Self {
24            flags,
25            signature_records,
26        }
27    }
28}
29
30impl FontWrite for Dsig {
31    #[allow(clippy::unnecessary_cast)]
32    fn write_into(&self, writer: &mut TableWriter) {
33        (1 as u32).write_into(writer);
34        (u16::try_from(array_len(&self.signature_records)).unwrap()).write_into(writer);
35        self.flags.write_into(writer);
36        self.signature_records.write_into(writer);
37    }
38    fn table_type(&self) -> TableType {
39        TableType::TopLevel(Dsig::TAG)
40    }
41}
42
43impl Validate for Dsig {
44    fn validate_impl(&self, ctx: &mut ValidationCtx) {
45        ctx.in_table("Dsig", |ctx| {
46            ctx.in_field("signature_records", |ctx| {
47                if self.signature_records.len() > to_usize(u16::MAX) {
48                    ctx.report("array exceeds max length");
49                }
50                self.signature_records.validate_impl(ctx);
51            });
52        })
53    }
54}
55
56impl TopLevelTable for Dsig {
57    const TAG: Tag = Tag::new(b"DSIG");
58}
59
60impl<'a> FromObjRef<read_fonts::tables::dsig::Dsig<'a>> for Dsig {
61    fn from_obj_ref(obj: &read_fonts::tables::dsig::Dsig<'a>, _: FontData) -> Self {
62        let offset_data = obj.offset_data();
63        Dsig {
64            flags: obj.flags(),
65            signature_records: obj.signature_records().to_owned_obj(offset_data),
66        }
67    }
68}
69
70#[allow(clippy::needless_lifetimes)]
71impl<'a> FromTableRef<read_fonts::tables::dsig::Dsig<'a>> for Dsig {}
72
73impl ReadArgs for Dsig {
74    type Args = ();
75}
76
77impl<'a> FontRead<'a> for Dsig {
78    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
79        <read_fonts::tables::dsig::Dsig as FontRead>::read(data).map(|x| x.to_owned_table())
80    }
81}
82
83impl FontWrite for PermissionFlags {
84    fn write_into(&self, writer: &mut TableWriter) {
85        writer.write_slice(&self.bits().to_be_bytes())
86    }
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))]
92pub struct SignatureRecord {
93    /// Offset to the signature block from the beginning of the table
94    pub signature_block: OffsetMarker<SignatureBlockFormat1, WIDTH_32>,
95}
96
97impl SignatureRecord {
98    /// Construct a new `SignatureRecord`
99    pub fn new(signature_block: SignatureBlockFormat1) -> Self {
100        Self {
101            signature_block: signature_block.into(),
102        }
103    }
104}
105
106impl FontWrite for SignatureRecord {
107    #[allow(clippy::unnecessary_cast)]
108    fn write_into(&self, writer: &mut TableWriter) {
109        (1 as u32).write_into(writer);
110        (self.compute_signature_block_len() as u32).write_into(writer);
111        self.signature_block.write_into(writer);
112    }
113    fn table_type(&self) -> TableType {
114        TableType::Named("SignatureRecord")
115    }
116}
117
118impl Validate for SignatureRecord {
119    fn validate_impl(&self, ctx: &mut ValidationCtx) {
120        ctx.in_table("SignatureRecord", |ctx| {
121            ctx.in_field("signature_block", |ctx| {
122                self.signature_block.validate_impl(ctx);
123            });
124        })
125    }
126}
127
128impl FromObjRef<read_fonts::tables::dsig::SignatureRecord> for SignatureRecord {
129    fn from_obj_ref(
130        obj: &read_fonts::tables::dsig::SignatureRecord,
131        offset_data: FontData,
132    ) -> Self {
133        SignatureRecord {
134            signature_block: obj.signature_block(offset_data).to_owned_table(),
135        }
136    }
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))]
142pub struct SignatureBlockFormat1 {
143    /// PKCS#7 packet
144    pub signature: Vec<u8>,
145}
146
147impl SignatureBlockFormat1 {
148    /// Construct a new `SignatureBlockFormat1`
149    pub fn new(signature: Vec<u8>) -> Self {
150        Self { signature }
151    }
152}
153
154impl FontWrite for SignatureBlockFormat1 {
155    #[allow(clippy::unnecessary_cast)]
156    fn write_into(&self, writer: &mut TableWriter) {
157        (0 as u16).write_into(writer);
158        (0 as u16).write_into(writer);
159        (u32::try_from(array_len(&self.signature)).unwrap()).write_into(writer);
160        self.signature.write_into(writer);
161    }
162    fn table_type(&self) -> TableType {
163        TableType::Named("SignatureBlockFormat1")
164    }
165}
166
167impl Validate for SignatureBlockFormat1 {
168    fn validate_impl(&self, ctx: &mut ValidationCtx) {
169        ctx.in_table("SignatureBlockFormat1", |ctx| {
170            ctx.in_field("signature", |ctx| {
171                if self.signature.len() > to_usize(u32::MAX) {
172                    ctx.report("array exceeds max length");
173                }
174            });
175        })
176    }
177}
178
179impl<'a> FromObjRef<read_fonts::tables::dsig::SignatureBlockFormat1<'a>> for SignatureBlockFormat1 {
180    fn from_obj_ref(
181        obj: &read_fonts::tables::dsig::SignatureBlockFormat1<'a>,
182        _: FontData,
183    ) -> Self {
184        let offset_data = obj.offset_data();
185        SignatureBlockFormat1 {
186            signature: obj.signature().to_owned_obj(offset_data),
187        }
188    }
189}
190
191#[allow(clippy::needless_lifetimes)]
192impl<'a> FromTableRef<read_fonts::tables::dsig::SignatureBlockFormat1<'a>>
193    for SignatureBlockFormat1
194{
195}
196
197impl ReadArgs for SignatureBlockFormat1 {
198    type Args = ();
199}
200
201impl<'a> FontRead<'a> for SignatureBlockFormat1 {
202    fn read_with_args(data: FontData<'a>, _: ()) -> Result<Self, ReadError> {
203        <read_fonts::tables::dsig::SignatureBlockFormat1 as FontRead>::read(data)
204            .map(|x| x.to_owned_table())
205    }
206}