Skip to main content

sbp/messages/
signing.rs

1// Copyright (C) 2015-2021 Swift Navigation Inc.
2// Contact: https://support.swiftnav.com
3//
4// This source is subject to the license found in the file 'LICENSE' which must
5// be distributed together with this source. All other rights reserved.
6//
7// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
8// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
9// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
10
11//****************************************************************************
12// Automatically generated from yaml/swiftnav/sbp/signing.yaml
13// with generate.py. Please do not hand edit!
14//****************************************************************************/
15//! Messages relating to signatures
16pub use ecdsa_signature::ECDSASignature;
17pub use msg_aes_cmac_signature::MsgAesCmacSignature;
18pub use msg_certificate_chain::MsgCertificateChain;
19pub use msg_certificate_chain_dep::MsgCertificateChainDep;
20pub use msg_ecdsa_certificate::MsgEcdsaCertificate;
21pub use msg_ecdsa_signature::MsgEcdsaSignature;
22pub use msg_ecdsa_signature_dep_a::MsgEcdsaSignatureDepA;
23pub use msg_ecdsa_signature_dep_b::MsgEcdsaSignatureDepB;
24pub use msg_ed25519_certificate_dep::MsgEd25519CertificateDep;
25pub use msg_ed25519_signature_dep_a::MsgEd25519SignatureDepA;
26pub use msg_ed25519_signature_dep_b::MsgEd25519SignatureDepB;
27pub use utc_time::UtcTime;
28
29pub mod ecdsa_signature {
30    #![allow(unused_imports)]
31
32    use super::*;
33    use crate::messages::lib::*;
34    /// ECDSA signature
35    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
36    #[allow(clippy::derive_partial_eq_without_eq)]
37    #[derive(Debug, PartialEq, Clone)]
38    pub struct ECDSASignature {
39        /// Number of bytes to use of the signature field.  The DER encoded
40        /// signature has a maximum size of 72 bytes but can vary between 70 and 72
41        /// bytes in length.
42        #[cfg_attr(feature = "serde", serde(rename = "len"))]
43        pub len: u8,
44        /// DER encoded ECDSA signature for the messages using SHA-256 as the digest
45        /// algorithm.
46        #[cfg_attr(feature = "serde", serde(with = "BigArray", rename = "data"))]
47        pub data: [u8; 72],
48    }
49
50    impl WireFormat for ECDSASignature {
51        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN + <[u8; 72] as WireFormat>::MIN_LEN;
52        fn len(&self) -> usize {
53            WireFormat::len(&self.len) + WireFormat::len(&self.data)
54        }
55        fn write<B: BufMut>(&self, buf: &mut B) {
56            WireFormat::write(&self.len, buf);
57            WireFormat::write(&self.data, buf);
58        }
59        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
60            ECDSASignature {
61                len: WireFormat::parse_unchecked(buf),
62                data: WireFormat::parse_unchecked(buf),
63            }
64        }
65    }
66}
67
68pub mod msg_aes_cmac_signature {
69    #![allow(unused_imports)]
70
71    use super::*;
72    use crate::messages::lib::*;
73
74    /// AES-CMAC 128 digital signature
75    ///
76    /// Digital signature using AES-CMAC 128 algorithm used for data integrity.
77    ///
78    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
79    #[allow(clippy::derive_partial_eq_without_eq)]
80    #[derive(Debug, PartialEq, Clone)]
81    pub struct MsgAesCmacSignature {
82        /// The message sender_id
83        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
84        pub sender_id: Option<u16>,
85        /// Signature message counter. Zero indexed and incremented with each
86        /// signature message.  The counter will not increment if this message was
87        /// in response to an on demand request.  The counter will roll over after
88        /// 256 messages. Upon connection, the value of the counter may not
89        /// initially be zero.
90        #[cfg_attr(feature = "serde", serde(rename = "stream_counter"))]
91        pub stream_counter: u8,
92        /// On demand message counter. Zero indexed and incremented with each
93        /// signature message sent in response to an on demand message. The counter
94        /// will roll over after 256 messages.  Upon connection, the value of the
95        /// counter may not initially be zero.
96        #[cfg_attr(feature = "serde", serde(rename = "on_demand_counter"))]
97        pub on_demand_counter: u8,
98        /// The last 4 bytes of the certificate's SHA-1 fingerprint
99        #[cfg_attr(feature = "serde", serde(rename = "certificate_id"))]
100        pub certificate_id: [u8; 4],
101        /// Signature (CMAC tag value)
102        #[cfg_attr(feature = "serde", serde(rename = "signature"))]
103        pub signature: [u8; 16],
104        /// Describes the format of the 'signed_messages' field.
105        #[cfg_attr(feature = "serde", serde(rename = "flags"))]
106        pub flags: u8,
107        /// CRCs of the messages covered by this signature.  For Skylark, which
108        /// delivers SBP messages wrapped in Swift's proprietary RTCM message, these
109        /// are the 24-bit CRCs from the RTCM message framing. For SBP only streams,
110        /// this will be 16-bit CRCs from the SBP framing.  See the `flags` field to
111        /// determine the type of CRCs covered.
112        #[cfg_attr(feature = "serde", serde(rename = "signed_messages"))]
113        pub signed_messages: Vec<u8>,
114    }
115
116    impl MsgAesCmacSignature {
117        /// Gets the [CrcType][self::CrcType] stored in the `flags` bitfield.
118        ///
119        /// Returns `Ok` if the bitrange contains a known `CrcType` variant.
120        /// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
121        /// or because new variants of `CrcType` were added.
122        pub fn crc_type(&self) -> Result<CrcType, u8> {
123            get_bit_range!(self.flags, u8, u8, 1, 0).try_into()
124        }
125
126        /// Set the bitrange corresponding to the [CrcType][CrcType] of the `flags` bitfield.
127        pub fn set_crc_type(&mut self, crc_type: CrcType) {
128            set_bit_range!(&mut self.flags, crc_type, u8, u8, 1, 0);
129        }
130    }
131
132    impl ConcreteMessage for MsgAesCmacSignature {
133        const MESSAGE_TYPE: u16 = 3088;
134        const MESSAGE_NAME: &'static str = "MSG_AES_CMAC_SIGNATURE";
135    }
136
137    impl SbpMessage for MsgAesCmacSignature {
138        fn message_name(&self) -> &'static str {
139            <Self as ConcreteMessage>::MESSAGE_NAME
140        }
141        fn message_type(&self) -> Option<u16> {
142            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
143        }
144        fn sender_id(&self) -> Option<u16> {
145            self.sender_id
146        }
147        fn set_sender_id(&mut self, new_id: u16) {
148            self.sender_id = Some(new_id);
149        }
150        fn encoded_len(&self) -> usize {
151            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
152        }
153        fn is_valid(&self) -> bool {
154            true
155        }
156        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
157            Ok(self)
158        }
159    }
160
161    impl FriendlyName for MsgAesCmacSignature {
162        fn friendly_name() -> &'static str {
163            "AES CMAC SIGNATURE"
164        }
165    }
166
167    impl TryFrom<Sbp> for MsgAesCmacSignature {
168        type Error = TryFromSbpError;
169        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
170            match msg {
171                Sbp::MsgAesCmacSignature(m) => Ok(m),
172                _ => Err(TryFromSbpError(msg)),
173            }
174        }
175    }
176
177    impl WireFormat for MsgAesCmacSignature {
178        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
179            + <u8 as WireFormat>::MIN_LEN
180            + <[u8; 4] as WireFormat>::MIN_LEN
181            + <[u8; 16] as WireFormat>::MIN_LEN
182            + <u8 as WireFormat>::MIN_LEN
183            + <Vec<u8> as WireFormat>::MIN_LEN;
184        fn len(&self) -> usize {
185            WireFormat::len(&self.stream_counter)
186                + WireFormat::len(&self.on_demand_counter)
187                + WireFormat::len(&self.certificate_id)
188                + WireFormat::len(&self.signature)
189                + WireFormat::len(&self.flags)
190                + WireFormat::len(&self.signed_messages)
191        }
192        fn write<B: BufMut>(&self, buf: &mut B) {
193            WireFormat::write(&self.stream_counter, buf);
194            WireFormat::write(&self.on_demand_counter, buf);
195            WireFormat::write(&self.certificate_id, buf);
196            WireFormat::write(&self.signature, buf);
197            WireFormat::write(&self.flags, buf);
198            WireFormat::write(&self.signed_messages, buf);
199        }
200        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
201            MsgAesCmacSignature {
202                sender_id: None,
203                stream_counter: WireFormat::parse_unchecked(buf),
204                on_demand_counter: WireFormat::parse_unchecked(buf),
205                certificate_id: WireFormat::parse_unchecked(buf),
206                signature: WireFormat::parse_unchecked(buf),
207                flags: WireFormat::parse_unchecked(buf),
208                signed_messages: WireFormat::parse_unchecked(buf),
209            }
210        }
211    }
212
213    /// CRC type
214    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
215    pub enum CrcType {
216        /// 24-bit CRCs from RTCM framing
217        _24BitCrcsFromRtcmFraming = 0,
218
219        /// 16-bit CRCs from SBP framing
220        _16BitCrcsFromSbpFraming = 1,
221    }
222
223    impl std::fmt::Display for CrcType {
224        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
225            match self {
226                CrcType::_24BitCrcsFromRtcmFraming => f.write_str("24-bit CRCs from RTCM framing"),
227                CrcType::_16BitCrcsFromSbpFraming => f.write_str("16-bit CRCs from SBP framing"),
228            }
229        }
230    }
231
232    impl TryFrom<u8> for CrcType {
233        type Error = u8;
234        fn try_from(i: u8) -> Result<Self, u8> {
235            match i {
236                0 => Ok(CrcType::_24BitCrcsFromRtcmFraming),
237                1 => Ok(CrcType::_16BitCrcsFromSbpFraming),
238                i => Err(i),
239            }
240        }
241    }
242}
243
244pub mod msg_certificate_chain {
245    #![allow(unused_imports)]
246
247    use super::*;
248    use crate::messages::lib::*;
249    /// The certificate chain
250    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
251    #[allow(clippy::derive_partial_eq_without_eq)]
252    #[derive(Debug, PartialEq, Clone)]
253    pub struct MsgCertificateChain {
254        /// The message sender_id
255        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
256        pub sender_id: Option<u16>,
257        /// SHA-1 fingerprint of the root certificate
258        #[cfg_attr(feature = "serde", serde(rename = "root_certificate"))]
259        pub root_certificate: [u8; 20],
260        /// SHA-1 fingerprint of the intermediate certificate
261        #[cfg_attr(feature = "serde", serde(rename = "intermediate_certificate"))]
262        pub intermediate_certificate: [u8; 20],
263        /// SHA-1 fingerprint of the corrections certificate
264        #[cfg_attr(feature = "serde", serde(rename = "corrections_certificate"))]
265        pub corrections_certificate: [u8; 20],
266        /// The time after which the signature given is no longer valid.
267        /// Implementors should consult a time source (such as GNSS) to check if the
268        /// current time is later than the expiration time, if the condition is
269        /// true, signatures in the stream should not be considered valid.
270        #[cfg_attr(feature = "serde", serde(rename = "expiration"))]
271        pub expiration: UtcTime,
272        /// Signature (created by the root certificate) over the concatenation of
273        /// the SBP payload bytes preceding this field. That is, the concatenation
274        /// of `root_certificate`, `intermediate_certificate`,
275        /// `corrections_certificate` and `expiration`.  This certificate chain
276        /// (allow list) can also be validated by fetching it from
277        /// `http(s)://certs.swiftnav.com/chain`.
278        #[cfg_attr(feature = "serde", serde(rename = "signature"))]
279        pub signature: ECDSASignature,
280    }
281
282    impl ConcreteMessage for MsgCertificateChain {
283        const MESSAGE_TYPE: u16 = 3081;
284        const MESSAGE_NAME: &'static str = "MSG_CERTIFICATE_CHAIN";
285    }
286
287    impl SbpMessage for MsgCertificateChain {
288        fn message_name(&self) -> &'static str {
289            <Self as ConcreteMessage>::MESSAGE_NAME
290        }
291        fn message_type(&self) -> Option<u16> {
292            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
293        }
294        fn sender_id(&self) -> Option<u16> {
295            self.sender_id
296        }
297        fn set_sender_id(&mut self, new_id: u16) {
298            self.sender_id = Some(new_id);
299        }
300        fn encoded_len(&self) -> usize {
301            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
302        }
303        fn is_valid(&self) -> bool {
304            true
305        }
306        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
307            Ok(self)
308        }
309    }
310
311    impl FriendlyName for MsgCertificateChain {
312        fn friendly_name() -> &'static str {
313            "CERTIFICATE CHAIN"
314        }
315    }
316
317    impl TryFrom<Sbp> for MsgCertificateChain {
318        type Error = TryFromSbpError;
319        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
320            match msg {
321                Sbp::MsgCertificateChain(m) => Ok(m),
322                _ => Err(TryFromSbpError(msg)),
323            }
324        }
325    }
326
327    impl WireFormat for MsgCertificateChain {
328        const MIN_LEN: usize = <[u8; 20] as WireFormat>::MIN_LEN
329            + <[u8; 20] as WireFormat>::MIN_LEN
330            + <[u8; 20] as WireFormat>::MIN_LEN
331            + <UtcTime as WireFormat>::MIN_LEN
332            + <ECDSASignature as WireFormat>::MIN_LEN;
333        fn len(&self) -> usize {
334            WireFormat::len(&self.root_certificate)
335                + WireFormat::len(&self.intermediate_certificate)
336                + WireFormat::len(&self.corrections_certificate)
337                + WireFormat::len(&self.expiration)
338                + WireFormat::len(&self.signature)
339        }
340        fn write<B: BufMut>(&self, buf: &mut B) {
341            WireFormat::write(&self.root_certificate, buf);
342            WireFormat::write(&self.intermediate_certificate, buf);
343            WireFormat::write(&self.corrections_certificate, buf);
344            WireFormat::write(&self.expiration, buf);
345            WireFormat::write(&self.signature, buf);
346        }
347        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
348            MsgCertificateChain {
349                sender_id: None,
350                root_certificate: WireFormat::parse_unchecked(buf),
351                intermediate_certificate: WireFormat::parse_unchecked(buf),
352                corrections_certificate: WireFormat::parse_unchecked(buf),
353                expiration: WireFormat::parse_unchecked(buf),
354                signature: WireFormat::parse_unchecked(buf),
355            }
356        }
357    }
358}
359
360pub mod msg_certificate_chain_dep {
361    #![allow(unused_imports)]
362
363    use super::*;
364    use crate::messages::lib::*;
365
366    /// Deprecated
367    ///
368    /// Deprecated.
369    ///
370    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
371    #[allow(clippy::derive_partial_eq_without_eq)]
372    #[derive(Debug, PartialEq, Clone)]
373    pub struct MsgCertificateChainDep {
374        /// The message sender_id
375        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
376        pub sender_id: Option<u16>,
377        /// SHA-1 fingerprint of the root certificate
378        #[cfg_attr(feature = "serde", serde(rename = "root_certificate"))]
379        pub root_certificate: [u8; 20],
380        /// SHA-1 fingerprint of the intermediate certificate
381        #[cfg_attr(feature = "serde", serde(rename = "intermediate_certificate"))]
382        pub intermediate_certificate: [u8; 20],
383        /// SHA-1 fingerprint of the corrections certificate
384        #[cfg_attr(feature = "serde", serde(rename = "corrections_certificate"))]
385        pub corrections_certificate: [u8; 20],
386        /// The certificate chain comprised of three fingerprints: root certificate,
387        /// intermediate certificate and corrections certificate.
388        #[cfg_attr(feature = "serde", serde(rename = "expiration"))]
389        pub expiration: UtcTime,
390        /// An ECDSA signature (created by the root certificate) over the
391        /// concatenation of the SBP payload bytes preceding this field. That is,
392        /// the concatenation of `root_certificate`, `intermediate_certificate`,
393        /// `corrections_certificate` and `expiration`.  This certificate chain
394        /// (allow list) can also be validated by fetching it from
395        /// `http(s)://certs.swiftnav.com/chain`.
396        #[cfg_attr(feature = "serde", serde(with = "BigArray", rename = "signature"))]
397        pub signature: [u8; 64],
398    }
399
400    impl ConcreteMessage for MsgCertificateChainDep {
401        const MESSAGE_TYPE: u16 = 3077;
402        const MESSAGE_NAME: &'static str = "MSG_CERTIFICATE_CHAIN_DEP";
403    }
404
405    impl SbpMessage for MsgCertificateChainDep {
406        fn message_name(&self) -> &'static str {
407            <Self as ConcreteMessage>::MESSAGE_NAME
408        }
409        fn message_type(&self) -> Option<u16> {
410            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
411        }
412        fn sender_id(&self) -> Option<u16> {
413            self.sender_id
414        }
415        fn set_sender_id(&mut self, new_id: u16) {
416            self.sender_id = Some(new_id);
417        }
418        fn encoded_len(&self) -> usize {
419            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
420        }
421        fn is_valid(&self) -> bool {
422            true
423        }
424        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
425            Ok(self)
426        }
427    }
428
429    impl FriendlyName for MsgCertificateChainDep {
430        fn friendly_name() -> &'static str {
431            "CERTIFICATE CHAIN DEP"
432        }
433    }
434
435    impl TryFrom<Sbp> for MsgCertificateChainDep {
436        type Error = TryFromSbpError;
437        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
438            match msg {
439                Sbp::MsgCertificateChainDep(m) => Ok(m),
440                _ => Err(TryFromSbpError(msg)),
441            }
442        }
443    }
444
445    impl WireFormat for MsgCertificateChainDep {
446        const MIN_LEN: usize = <[u8; 20] as WireFormat>::MIN_LEN
447            + <[u8; 20] as WireFormat>::MIN_LEN
448            + <[u8; 20] as WireFormat>::MIN_LEN
449            + <UtcTime as WireFormat>::MIN_LEN
450            + <[u8; 64] as WireFormat>::MIN_LEN;
451        fn len(&self) -> usize {
452            WireFormat::len(&self.root_certificate)
453                + WireFormat::len(&self.intermediate_certificate)
454                + WireFormat::len(&self.corrections_certificate)
455                + WireFormat::len(&self.expiration)
456                + WireFormat::len(&self.signature)
457        }
458        fn write<B: BufMut>(&self, buf: &mut B) {
459            WireFormat::write(&self.root_certificate, buf);
460            WireFormat::write(&self.intermediate_certificate, buf);
461            WireFormat::write(&self.corrections_certificate, buf);
462            WireFormat::write(&self.expiration, buf);
463            WireFormat::write(&self.signature, buf);
464        }
465        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
466            MsgCertificateChainDep {
467                sender_id: None,
468                root_certificate: WireFormat::parse_unchecked(buf),
469                intermediate_certificate: WireFormat::parse_unchecked(buf),
470                corrections_certificate: WireFormat::parse_unchecked(buf),
471                expiration: WireFormat::parse_unchecked(buf),
472                signature: WireFormat::parse_unchecked(buf),
473            }
474        }
475    }
476}
477
478pub mod msg_ecdsa_certificate {
479    #![allow(unused_imports)]
480
481    use super::*;
482    use crate::messages::lib::*;
483
484    /// An ECDSA certificate split over multiple messages
485    ///
486    /// A DER encoded x.509 ECDSA-256 certificate (using curve secp256r1).
487    ///
488    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
489    #[allow(clippy::derive_partial_eq_without_eq)]
490    #[derive(Debug, PartialEq, Clone)]
491    pub struct MsgEcdsaCertificate {
492        /// The message sender_id
493        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
494        pub sender_id: Option<u16>,
495        /// Total number messages that make up the certificate. The first nibble
496        /// (mask 0xF0 or left shifted by 4 bits) is the size of the sequence (n),
497        /// second nibble (mask 0x0F) is the zero-indexed counter (ith packet of n).
498        #[cfg_attr(feature = "serde", serde(rename = "n_msg"))]
499        pub n_msg: u8,
500        /// The last 4 bytes of the certificate's SHA-1 fingerprint
501        #[cfg_attr(feature = "serde", serde(rename = "certificate_id"))]
502        pub certificate_id: [u8; 4],
503        #[cfg_attr(feature = "serde", serde(rename = "flags"))]
504        pub flags: u8,
505        /// DER encoded x.509 ECDSA certificate bytes
506        #[cfg_attr(feature = "serde", serde(rename = "certificate_bytes"))]
507        pub certificate_bytes: Vec<u8>,
508    }
509
510    impl MsgEcdsaCertificate {
511        /// Gets the [CertificateType][self::CertificateType] stored in the `flags` bitfield.
512        ///
513        /// Returns `Ok` if the bitrange contains a known `CertificateType` variant.
514        /// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
515        /// or because new variants of `CertificateType` were added.
516        pub fn certificate_type(&self) -> Result<CertificateType, u8> {
517            get_bit_range!(self.flags, u8, u8, 2, 0).try_into()
518        }
519
520        /// Set the bitrange corresponding to the [CertificateType][CertificateType] of the `flags` bitfield.
521        pub fn set_certificate_type(&mut self, certificate_type: CertificateType) {
522            set_bit_range!(&mut self.flags, certificate_type, u8, u8, 2, 0);
523        }
524    }
525
526    impl ConcreteMessage for MsgEcdsaCertificate {
527        const MESSAGE_TYPE: u16 = 3076;
528        const MESSAGE_NAME: &'static str = "MSG_ECDSA_CERTIFICATE";
529    }
530
531    impl SbpMessage for MsgEcdsaCertificate {
532        fn message_name(&self) -> &'static str {
533            <Self as ConcreteMessage>::MESSAGE_NAME
534        }
535        fn message_type(&self) -> Option<u16> {
536            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
537        }
538        fn sender_id(&self) -> Option<u16> {
539            self.sender_id
540        }
541        fn set_sender_id(&mut self, new_id: u16) {
542            self.sender_id = Some(new_id);
543        }
544        fn encoded_len(&self) -> usize {
545            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
546        }
547        fn is_valid(&self) -> bool {
548            true
549        }
550        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
551            Ok(self)
552        }
553    }
554
555    impl FriendlyName for MsgEcdsaCertificate {
556        fn friendly_name() -> &'static str {
557            "ECDSA CERTIFICATE"
558        }
559    }
560
561    impl TryFrom<Sbp> for MsgEcdsaCertificate {
562        type Error = TryFromSbpError;
563        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
564            match msg {
565                Sbp::MsgEcdsaCertificate(m) => Ok(m),
566                _ => Err(TryFromSbpError(msg)),
567            }
568        }
569    }
570
571    impl WireFormat for MsgEcdsaCertificate {
572        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
573            + <[u8; 4] as WireFormat>::MIN_LEN
574            + <u8 as WireFormat>::MIN_LEN
575            + <Vec<u8> as WireFormat>::MIN_LEN;
576        fn len(&self) -> usize {
577            WireFormat::len(&self.n_msg)
578                + WireFormat::len(&self.certificate_id)
579                + WireFormat::len(&self.flags)
580                + WireFormat::len(&self.certificate_bytes)
581        }
582        fn write<B: BufMut>(&self, buf: &mut B) {
583            WireFormat::write(&self.n_msg, buf);
584            WireFormat::write(&self.certificate_id, buf);
585            WireFormat::write(&self.flags, buf);
586            WireFormat::write(&self.certificate_bytes, buf);
587        }
588        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
589            MsgEcdsaCertificate {
590                sender_id: None,
591                n_msg: WireFormat::parse_unchecked(buf),
592                certificate_id: WireFormat::parse_unchecked(buf),
593                flags: WireFormat::parse_unchecked(buf),
594                certificate_bytes: WireFormat::parse_unchecked(buf),
595            }
596        }
597    }
598
599    /// Certificate type
600    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
601    pub enum CertificateType {
602        /// Corrections certificate
603        CorrectionsCertificate = 0,
604
605        /// Root certificate
606        RootCertificate = 1,
607
608        /// Intermediate certificate
609        IntermediateCertificate = 2,
610    }
611
612    impl std::fmt::Display for CertificateType {
613        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
614            match self {
615                CertificateType::CorrectionsCertificate => f.write_str("Corrections certificate"),
616                CertificateType::RootCertificate => f.write_str("Root certificate"),
617                CertificateType::IntermediateCertificate => f.write_str("Intermediate certificate"),
618            }
619        }
620    }
621
622    impl TryFrom<u8> for CertificateType {
623        type Error = u8;
624        fn try_from(i: u8) -> Result<Self, u8> {
625            match i {
626                0 => Ok(CertificateType::CorrectionsCertificate),
627                1 => Ok(CertificateType::RootCertificate),
628                2 => Ok(CertificateType::IntermediateCertificate),
629                i => Err(i),
630            }
631        }
632    }
633}
634
635pub mod msg_ecdsa_signature {
636    #![allow(unused_imports)]
637
638    use super::*;
639    use crate::messages::lib::*;
640
641    /// An ECDSA signature
642    ///
643    /// An ECDSA-256 signature using SHA-256 as the message digest algorithm.
644    ///
645    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
646    #[allow(clippy::derive_partial_eq_without_eq)]
647    #[derive(Debug, PartialEq, Clone)]
648    pub struct MsgEcdsaSignature {
649        /// The message sender_id
650        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
651        pub sender_id: Option<u16>,
652        /// Describes the format of the 'signed_messages' field.
653        #[cfg_attr(feature = "serde", serde(rename = "flags"))]
654        pub flags: u8,
655        /// Signature message counter. Zero indexed and incremented with each
656        /// signature message.  The counter will not increment if this message was
657        /// in response to an on demand request.  The counter will roll over after
658        /// 256 messages. Upon connection, the value of the counter may not
659        /// initially be zero.
660        #[cfg_attr(feature = "serde", serde(rename = "stream_counter"))]
661        pub stream_counter: u8,
662        /// On demand message counter. Zero indexed and incremented with each
663        /// signature message sent in response to an on demand message. The counter
664        /// will roll over after 256 messages.  Upon connection, the value of the
665        /// counter may not initially be zero.
666        #[cfg_attr(feature = "serde", serde(rename = "on_demand_counter"))]
667        pub on_demand_counter: u8,
668        /// The last 4 bytes of the certificate's SHA-1 fingerprint
669        #[cfg_attr(feature = "serde", serde(rename = "certificate_id"))]
670        pub certificate_id: [u8; 4],
671        /// Signature over the frames of this message group.
672        #[cfg_attr(feature = "serde", serde(rename = "signature"))]
673        pub signature: ECDSASignature,
674        /// CRCs of the messages covered by this signature.  For Skylark, which
675        /// delivers SBP messages wrapped in Swift's proprietary RTCM message, these
676        /// are the 24-bit CRCs from the RTCM message framing. For SBP only streams,
677        /// this will be 16-bit CRCs from the SBP framing.  See the `flags` field to
678        /// determine the type of CRCs covered.
679        #[cfg_attr(feature = "serde", serde(rename = "signed_messages"))]
680        pub signed_messages: Vec<u8>,
681    }
682
683    impl MsgEcdsaSignature {
684        /// Gets the [CrcType][self::CrcType] stored in the `flags` bitfield.
685        ///
686        /// Returns `Ok` if the bitrange contains a known `CrcType` variant.
687        /// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
688        /// or because new variants of `CrcType` were added.
689        pub fn crc_type(&self) -> Result<CrcType, u8> {
690            get_bit_range!(self.flags, u8, u8, 1, 0).try_into()
691        }
692
693        /// Set the bitrange corresponding to the [CrcType][CrcType] of the `flags` bitfield.
694        pub fn set_crc_type(&mut self, crc_type: CrcType) {
695            set_bit_range!(&mut self.flags, crc_type, u8, u8, 1, 0);
696        }
697    }
698
699    impl ConcreteMessage for MsgEcdsaSignature {
700        const MESSAGE_TYPE: u16 = 3080;
701        const MESSAGE_NAME: &'static str = "MSG_ECDSA_SIGNATURE";
702    }
703
704    impl SbpMessage for MsgEcdsaSignature {
705        fn message_name(&self) -> &'static str {
706            <Self as ConcreteMessage>::MESSAGE_NAME
707        }
708        fn message_type(&self) -> Option<u16> {
709            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
710        }
711        fn sender_id(&self) -> Option<u16> {
712            self.sender_id
713        }
714        fn set_sender_id(&mut self, new_id: u16) {
715            self.sender_id = Some(new_id);
716        }
717        fn encoded_len(&self) -> usize {
718            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
719        }
720        fn is_valid(&self) -> bool {
721            true
722        }
723        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
724            Ok(self)
725        }
726    }
727
728    impl FriendlyName for MsgEcdsaSignature {
729        fn friendly_name() -> &'static str {
730            "ECDSA SIGNATURE"
731        }
732    }
733
734    impl TryFrom<Sbp> for MsgEcdsaSignature {
735        type Error = TryFromSbpError;
736        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
737            match msg {
738                Sbp::MsgEcdsaSignature(m) => Ok(m),
739                _ => Err(TryFromSbpError(msg)),
740            }
741        }
742    }
743
744    impl WireFormat for MsgEcdsaSignature {
745        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
746            + <u8 as WireFormat>::MIN_LEN
747            + <u8 as WireFormat>::MIN_LEN
748            + <[u8; 4] as WireFormat>::MIN_LEN
749            + <ECDSASignature as WireFormat>::MIN_LEN
750            + <Vec<u8> as WireFormat>::MIN_LEN;
751        fn len(&self) -> usize {
752            WireFormat::len(&self.flags)
753                + WireFormat::len(&self.stream_counter)
754                + WireFormat::len(&self.on_demand_counter)
755                + WireFormat::len(&self.certificate_id)
756                + WireFormat::len(&self.signature)
757                + WireFormat::len(&self.signed_messages)
758        }
759        fn write<B: BufMut>(&self, buf: &mut B) {
760            WireFormat::write(&self.flags, buf);
761            WireFormat::write(&self.stream_counter, buf);
762            WireFormat::write(&self.on_demand_counter, buf);
763            WireFormat::write(&self.certificate_id, buf);
764            WireFormat::write(&self.signature, buf);
765            WireFormat::write(&self.signed_messages, buf);
766        }
767        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
768            MsgEcdsaSignature {
769                sender_id: None,
770                flags: WireFormat::parse_unchecked(buf),
771                stream_counter: WireFormat::parse_unchecked(buf),
772                on_demand_counter: WireFormat::parse_unchecked(buf),
773                certificate_id: WireFormat::parse_unchecked(buf),
774                signature: WireFormat::parse_unchecked(buf),
775                signed_messages: WireFormat::parse_unchecked(buf),
776            }
777        }
778    }
779
780    /// CRC type
781    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
782    pub enum CrcType {
783        /// 24-bit CRCs from RTCM framing
784        _24BitCrcsFromRtcmFraming = 0,
785
786        /// 16-bit CRCs from SBP framing
787        _16BitCrcsFromSbpFraming = 1,
788    }
789
790    impl std::fmt::Display for CrcType {
791        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
792            match self {
793                CrcType::_24BitCrcsFromRtcmFraming => f.write_str("24-bit CRCs from RTCM framing"),
794                CrcType::_16BitCrcsFromSbpFraming => f.write_str("16-bit CRCs from SBP framing"),
795            }
796        }
797    }
798
799    impl TryFrom<u8> for CrcType {
800        type Error = u8;
801        fn try_from(i: u8) -> Result<Self, u8> {
802            match i {
803                0 => Ok(CrcType::_24BitCrcsFromRtcmFraming),
804                1 => Ok(CrcType::_16BitCrcsFromSbpFraming),
805                i => Err(i),
806            }
807        }
808    }
809}
810
811pub mod msg_ecdsa_signature_dep_a {
812    #![allow(unused_imports)]
813
814    use super::*;
815    use crate::messages::lib::*;
816
817    /// Deprecated
818    ///
819    /// Deprecated.
820    ///
821    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
822    #[allow(clippy::derive_partial_eq_without_eq)]
823    #[derive(Debug, PartialEq, Clone)]
824    pub struct MsgEcdsaSignatureDepA {
825        /// The message sender_id
826        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
827        pub sender_id: Option<u16>,
828        /// Describes the format of the 'signed_messages' field.
829        #[cfg_attr(feature = "serde", serde(rename = "flags"))]
830        pub flags: u8,
831        /// Signature message counter. Zero indexed and incremented with each
832        /// signature message.  The counter will not increment if this message was
833        /// in response to an on demand request.  The counter will roll over after
834        /// 256 messages. Upon connection, the value of the counter may not
835        /// initially be zero.
836        #[cfg_attr(feature = "serde", serde(rename = "stream_counter"))]
837        pub stream_counter: u8,
838        /// On demand message counter. Zero indexed and incremented with each
839        /// signature message sent in response to an on demand message. The counter
840        /// will roll over after 256 messages.  Upon connection, the value of the
841        /// counter may not initially be zero.
842        #[cfg_attr(feature = "serde", serde(rename = "on_demand_counter"))]
843        pub on_demand_counter: u8,
844        /// The last 4 bytes of the certificate's SHA-1 fingerprint
845        #[cfg_attr(feature = "serde", serde(rename = "certificate_id"))]
846        pub certificate_id: [u8; 4],
847        /// ECDSA signature for the messages using SHA-256 as the digest algorithm.
848        #[cfg_attr(feature = "serde", serde(with = "BigArray", rename = "signature"))]
849        pub signature: [u8; 64],
850        /// CRCs of the messages covered by this signature.  For Skylark, which
851        /// delivers SBP messages wrapped in Swift's proprietary RTCM message, these
852        /// are the 24-bit CRCs from the RTCM message framing. For SBP only streams,
853        /// this will be 16-bit CRCs from the SBP framing.  See the `flags` field to
854        /// determine the type of CRCs covered.
855        #[cfg_attr(feature = "serde", serde(rename = "signed_messages"))]
856        pub signed_messages: Vec<u8>,
857    }
858
859    impl MsgEcdsaSignatureDepA {
860        /// Gets the [CrcType][self::CrcType] stored in the `flags` bitfield.
861        ///
862        /// Returns `Ok` if the bitrange contains a known `CrcType` variant.
863        /// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
864        /// or because new variants of `CrcType` were added.
865        pub fn crc_type(&self) -> Result<CrcType, u8> {
866            get_bit_range!(self.flags, u8, u8, 1, 0).try_into()
867        }
868
869        /// Set the bitrange corresponding to the [CrcType][CrcType] of the `flags` bitfield.
870        pub fn set_crc_type(&mut self, crc_type: CrcType) {
871            set_bit_range!(&mut self.flags, crc_type, u8, u8, 1, 0);
872        }
873    }
874
875    impl ConcreteMessage for MsgEcdsaSignatureDepA {
876        const MESSAGE_TYPE: u16 = 3078;
877        const MESSAGE_NAME: &'static str = "MSG_ECDSA_SIGNATURE_DEP_A";
878    }
879
880    impl SbpMessage for MsgEcdsaSignatureDepA {
881        fn message_name(&self) -> &'static str {
882            <Self as ConcreteMessage>::MESSAGE_NAME
883        }
884        fn message_type(&self) -> Option<u16> {
885            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
886        }
887        fn sender_id(&self) -> Option<u16> {
888            self.sender_id
889        }
890        fn set_sender_id(&mut self, new_id: u16) {
891            self.sender_id = Some(new_id);
892        }
893        fn encoded_len(&self) -> usize {
894            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
895        }
896        fn is_valid(&self) -> bool {
897            true
898        }
899        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
900            Ok(self)
901        }
902    }
903
904    impl FriendlyName for MsgEcdsaSignatureDepA {
905        fn friendly_name() -> &'static str {
906            "ECDSA SIGNATURE DEP A"
907        }
908    }
909
910    impl TryFrom<Sbp> for MsgEcdsaSignatureDepA {
911        type Error = TryFromSbpError;
912        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
913            match msg {
914                Sbp::MsgEcdsaSignatureDepA(m) => Ok(m),
915                _ => Err(TryFromSbpError(msg)),
916            }
917        }
918    }
919
920    impl WireFormat for MsgEcdsaSignatureDepA {
921        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
922            + <u8 as WireFormat>::MIN_LEN
923            + <u8 as WireFormat>::MIN_LEN
924            + <[u8; 4] as WireFormat>::MIN_LEN
925            + <[u8; 64] as WireFormat>::MIN_LEN
926            + <Vec<u8> as WireFormat>::MIN_LEN;
927        fn len(&self) -> usize {
928            WireFormat::len(&self.flags)
929                + WireFormat::len(&self.stream_counter)
930                + WireFormat::len(&self.on_demand_counter)
931                + WireFormat::len(&self.certificate_id)
932                + WireFormat::len(&self.signature)
933                + WireFormat::len(&self.signed_messages)
934        }
935        fn write<B: BufMut>(&self, buf: &mut B) {
936            WireFormat::write(&self.flags, buf);
937            WireFormat::write(&self.stream_counter, buf);
938            WireFormat::write(&self.on_demand_counter, buf);
939            WireFormat::write(&self.certificate_id, buf);
940            WireFormat::write(&self.signature, buf);
941            WireFormat::write(&self.signed_messages, buf);
942        }
943        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
944            MsgEcdsaSignatureDepA {
945                sender_id: None,
946                flags: WireFormat::parse_unchecked(buf),
947                stream_counter: WireFormat::parse_unchecked(buf),
948                on_demand_counter: WireFormat::parse_unchecked(buf),
949                certificate_id: WireFormat::parse_unchecked(buf),
950                signature: WireFormat::parse_unchecked(buf),
951                signed_messages: WireFormat::parse_unchecked(buf),
952            }
953        }
954    }
955
956    /// CRC type
957    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
958    pub enum CrcType {
959        /// 24-bit CRCs from RTCM framing
960        _24BitCrcsFromRtcmFraming = 0,
961
962        /// 16-bit CRCs from SBP framing
963        _16BitCrcsFromSbpFraming = 1,
964    }
965
966    impl std::fmt::Display for CrcType {
967        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
968            match self {
969                CrcType::_24BitCrcsFromRtcmFraming => f.write_str("24-bit CRCs from RTCM framing"),
970                CrcType::_16BitCrcsFromSbpFraming => f.write_str("16-bit CRCs from SBP framing"),
971            }
972        }
973    }
974
975    impl TryFrom<u8> for CrcType {
976        type Error = u8;
977        fn try_from(i: u8) -> Result<Self, u8> {
978            match i {
979                0 => Ok(CrcType::_24BitCrcsFromRtcmFraming),
980                1 => Ok(CrcType::_16BitCrcsFromSbpFraming),
981                i => Err(i),
982            }
983        }
984    }
985}
986
987pub mod msg_ecdsa_signature_dep_b {
988    #![allow(unused_imports)]
989
990    use super::*;
991    use crate::messages::lib::*;
992
993    /// Deprecated
994    ///
995    /// Deprecated.
996    ///
997    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
998    #[allow(clippy::derive_partial_eq_without_eq)]
999    #[derive(Debug, PartialEq, Clone)]
1000    pub struct MsgEcdsaSignatureDepB {
1001        /// The message sender_id
1002        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
1003        pub sender_id: Option<u16>,
1004        /// Describes the format of the 'signed_messages' field.
1005        #[cfg_attr(feature = "serde", serde(rename = "flags"))]
1006        pub flags: u8,
1007        /// Signature message counter. Zero indexed and incremented with each
1008        /// signature message.  The counter will not increment if this message was
1009        /// in response to an on demand request.  The counter will roll over after
1010        /// 256 messages. Upon connection, the value of the counter may not
1011        /// initially be zero.
1012        #[cfg_attr(feature = "serde", serde(rename = "stream_counter"))]
1013        pub stream_counter: u8,
1014        /// On demand message counter. Zero indexed and incremented with each
1015        /// signature message sent in response to an on demand message. The counter
1016        /// will roll over after 256 messages.  Upon connection, the value of the
1017        /// counter may not initially be zero.
1018        #[cfg_attr(feature = "serde", serde(rename = "on_demand_counter"))]
1019        pub on_demand_counter: u8,
1020        /// The last 4 bytes of the certificate's SHA-1 fingerprint
1021        #[cfg_attr(feature = "serde", serde(rename = "certificate_id"))]
1022        pub certificate_id: [u8; 4],
1023        /// Number of bytes to use of the signature field.  The DER encoded
1024        /// signature has a maximum size of 72 bytes but can vary between 70 and 72
1025        /// bytes in length.
1026        #[cfg_attr(feature = "serde", serde(rename = "n_signature_bytes"))]
1027        pub n_signature_bytes: u8,
1028        /// DER encoded ECDSA signature for the messages using SHA-256 as the digest
1029        /// algorithm.
1030        #[cfg_attr(feature = "serde", serde(with = "BigArray", rename = "signature"))]
1031        pub signature: [u8; 72],
1032        /// CRCs of the messages covered by this signature.  For Skylark, which
1033        /// delivers SBP messages wrapped in Swift's proprietary RTCM message, these
1034        /// are the 24-bit CRCs from the RTCM message framing. For SBP only streams,
1035        /// this will be 16-bit CRCs from the SBP framing.  See the `flags` field to
1036        /// determine the type of CRCs covered.
1037        #[cfg_attr(feature = "serde", serde(rename = "signed_messages"))]
1038        pub signed_messages: Vec<u8>,
1039    }
1040
1041    impl MsgEcdsaSignatureDepB {
1042        /// Gets the [CrcType][self::CrcType] stored in the `flags` bitfield.
1043        ///
1044        /// Returns `Ok` if the bitrange contains a known `CrcType` variant.
1045        /// Otherwise the value of the bitrange is returned as an `Err(u8)`. This may be because of a malformed message,
1046        /// or because new variants of `CrcType` were added.
1047        pub fn crc_type(&self) -> Result<CrcType, u8> {
1048            get_bit_range!(self.flags, u8, u8, 1, 0).try_into()
1049        }
1050
1051        /// Set the bitrange corresponding to the [CrcType][CrcType] of the `flags` bitfield.
1052        pub fn set_crc_type(&mut self, crc_type: CrcType) {
1053            set_bit_range!(&mut self.flags, crc_type, u8, u8, 1, 0);
1054        }
1055    }
1056
1057    impl ConcreteMessage for MsgEcdsaSignatureDepB {
1058        const MESSAGE_TYPE: u16 = 3079;
1059        const MESSAGE_NAME: &'static str = "MSG_ECDSA_SIGNATURE_DEP_B";
1060    }
1061
1062    impl SbpMessage for MsgEcdsaSignatureDepB {
1063        fn message_name(&self) -> &'static str {
1064            <Self as ConcreteMessage>::MESSAGE_NAME
1065        }
1066        fn message_type(&self) -> Option<u16> {
1067            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
1068        }
1069        fn sender_id(&self) -> Option<u16> {
1070            self.sender_id
1071        }
1072        fn set_sender_id(&mut self, new_id: u16) {
1073            self.sender_id = Some(new_id);
1074        }
1075        fn encoded_len(&self) -> usize {
1076            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
1077        }
1078        fn is_valid(&self) -> bool {
1079            true
1080        }
1081        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
1082            Ok(self)
1083        }
1084    }
1085
1086    impl FriendlyName for MsgEcdsaSignatureDepB {
1087        fn friendly_name() -> &'static str {
1088            "ECDSA SIGNATURE DEP B"
1089        }
1090    }
1091
1092    impl TryFrom<Sbp> for MsgEcdsaSignatureDepB {
1093        type Error = TryFromSbpError;
1094        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
1095            match msg {
1096                Sbp::MsgEcdsaSignatureDepB(m) => Ok(m),
1097                _ => Err(TryFromSbpError(msg)),
1098            }
1099        }
1100    }
1101
1102    impl WireFormat for MsgEcdsaSignatureDepB {
1103        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
1104            + <u8 as WireFormat>::MIN_LEN
1105            + <u8 as WireFormat>::MIN_LEN
1106            + <[u8; 4] as WireFormat>::MIN_LEN
1107            + <u8 as WireFormat>::MIN_LEN
1108            + <[u8; 72] as WireFormat>::MIN_LEN
1109            + <Vec<u8> as WireFormat>::MIN_LEN;
1110        fn len(&self) -> usize {
1111            WireFormat::len(&self.flags)
1112                + WireFormat::len(&self.stream_counter)
1113                + WireFormat::len(&self.on_demand_counter)
1114                + WireFormat::len(&self.certificate_id)
1115                + WireFormat::len(&self.n_signature_bytes)
1116                + WireFormat::len(&self.signature)
1117                + WireFormat::len(&self.signed_messages)
1118        }
1119        fn write<B: BufMut>(&self, buf: &mut B) {
1120            WireFormat::write(&self.flags, buf);
1121            WireFormat::write(&self.stream_counter, buf);
1122            WireFormat::write(&self.on_demand_counter, buf);
1123            WireFormat::write(&self.certificate_id, buf);
1124            WireFormat::write(&self.n_signature_bytes, buf);
1125            WireFormat::write(&self.signature, buf);
1126            WireFormat::write(&self.signed_messages, buf);
1127        }
1128        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
1129            MsgEcdsaSignatureDepB {
1130                sender_id: None,
1131                flags: WireFormat::parse_unchecked(buf),
1132                stream_counter: WireFormat::parse_unchecked(buf),
1133                on_demand_counter: WireFormat::parse_unchecked(buf),
1134                certificate_id: WireFormat::parse_unchecked(buf),
1135                n_signature_bytes: WireFormat::parse_unchecked(buf),
1136                signature: WireFormat::parse_unchecked(buf),
1137                signed_messages: WireFormat::parse_unchecked(buf),
1138            }
1139        }
1140    }
1141
1142    /// CRC type
1143    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
1144    pub enum CrcType {
1145        /// 24-bit CRCs from RTCM framing
1146        _24BitCrcsFromRtcmFraming = 0,
1147
1148        /// 16-bit CRCs from SBP framing
1149        _16BitCrcsFromSbpFraming = 1,
1150    }
1151
1152    impl std::fmt::Display for CrcType {
1153        fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
1154            match self {
1155                CrcType::_24BitCrcsFromRtcmFraming => f.write_str("24-bit CRCs from RTCM framing"),
1156                CrcType::_16BitCrcsFromSbpFraming => f.write_str("16-bit CRCs from SBP framing"),
1157            }
1158        }
1159    }
1160
1161    impl TryFrom<u8> for CrcType {
1162        type Error = u8;
1163        fn try_from(i: u8) -> Result<Self, u8> {
1164            match i {
1165                0 => Ok(CrcType::_24BitCrcsFromRtcmFraming),
1166                1 => Ok(CrcType::_16BitCrcsFromSbpFraming),
1167                i => Err(i),
1168            }
1169        }
1170    }
1171}
1172
1173pub mod msg_ed25519_certificate_dep {
1174    #![allow(unused_imports)]
1175
1176    use super::*;
1177    use crate::messages::lib::*;
1178
1179    /// Deprecated
1180    ///
1181    /// Deprecated.
1182    ///
1183    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1184    #[allow(clippy::derive_partial_eq_without_eq)]
1185    #[derive(Debug, PartialEq, Clone)]
1186    pub struct MsgEd25519CertificateDep {
1187        /// The message sender_id
1188        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
1189        pub sender_id: Option<u16>,
1190        /// Total number messages that make up the certificate. First nibble is the
1191        /// size of the sequence (n), second nibble is the zero-indexed counter (ith
1192        /// packet of n)
1193        #[cfg_attr(feature = "serde", serde(rename = "n_msg"))]
1194        pub n_msg: u8,
1195        /// SHA-1 fingerprint of the associated certificate.
1196        #[cfg_attr(feature = "serde", serde(rename = "fingerprint"))]
1197        pub fingerprint: [u8; 20],
1198        /// ED25519 certificate bytes.
1199        #[cfg_attr(feature = "serde", serde(rename = "certificate_bytes"))]
1200        pub certificate_bytes: Vec<u8>,
1201    }
1202
1203    impl ConcreteMessage for MsgEd25519CertificateDep {
1204        const MESSAGE_TYPE: u16 = 3074;
1205        const MESSAGE_NAME: &'static str = "MSG_ED25519_CERTIFICATE_DEP";
1206    }
1207
1208    impl SbpMessage for MsgEd25519CertificateDep {
1209        fn message_name(&self) -> &'static str {
1210            <Self as ConcreteMessage>::MESSAGE_NAME
1211        }
1212        fn message_type(&self) -> Option<u16> {
1213            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
1214        }
1215        fn sender_id(&self) -> Option<u16> {
1216            self.sender_id
1217        }
1218        fn set_sender_id(&mut self, new_id: u16) {
1219            self.sender_id = Some(new_id);
1220        }
1221        fn encoded_len(&self) -> usize {
1222            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
1223        }
1224        fn is_valid(&self) -> bool {
1225            true
1226        }
1227        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
1228            Ok(self)
1229        }
1230    }
1231
1232    impl FriendlyName for MsgEd25519CertificateDep {
1233        fn friendly_name() -> &'static str {
1234            "ED25519 CERTIFICATE DEP"
1235        }
1236    }
1237
1238    impl TryFrom<Sbp> for MsgEd25519CertificateDep {
1239        type Error = TryFromSbpError;
1240        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
1241            match msg {
1242                Sbp::MsgEd25519CertificateDep(m) => Ok(m),
1243                _ => Err(TryFromSbpError(msg)),
1244            }
1245        }
1246    }
1247
1248    impl WireFormat for MsgEd25519CertificateDep {
1249        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
1250            + <[u8; 20] as WireFormat>::MIN_LEN
1251            + <Vec<u8> as WireFormat>::MIN_LEN;
1252        fn len(&self) -> usize {
1253            WireFormat::len(&self.n_msg)
1254                + WireFormat::len(&self.fingerprint)
1255                + WireFormat::len(&self.certificate_bytes)
1256        }
1257        fn write<B: BufMut>(&self, buf: &mut B) {
1258            WireFormat::write(&self.n_msg, buf);
1259            WireFormat::write(&self.fingerprint, buf);
1260            WireFormat::write(&self.certificate_bytes, buf);
1261        }
1262        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
1263            MsgEd25519CertificateDep {
1264                sender_id: None,
1265                n_msg: WireFormat::parse_unchecked(buf),
1266                fingerprint: WireFormat::parse_unchecked(buf),
1267                certificate_bytes: WireFormat::parse_unchecked(buf),
1268            }
1269        }
1270    }
1271}
1272
1273pub mod msg_ed25519_signature_dep_a {
1274    #![allow(unused_imports)]
1275
1276    use super::*;
1277    use crate::messages::lib::*;
1278
1279    /// Deprecated
1280    ///
1281    /// Deprecated.
1282    ///
1283    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1284    #[allow(clippy::derive_partial_eq_without_eq)]
1285    #[derive(Debug, PartialEq, Clone)]
1286    pub struct MsgEd25519SignatureDepA {
1287        /// The message sender_id
1288        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
1289        pub sender_id: Option<u16>,
1290        /// ED25519 signature for messages.
1291        #[cfg_attr(feature = "serde", serde(with = "BigArray", rename = "signature"))]
1292        pub signature: [u8; 64],
1293        /// SHA-1 fingerprint of the associated certificate.
1294        #[cfg_attr(feature = "serde", serde(rename = "fingerprint"))]
1295        pub fingerprint: [u8; 20],
1296        /// CRCs of signed messages.
1297        #[cfg_attr(feature = "serde", serde(rename = "signed_messages"))]
1298        pub signed_messages: Vec<u32>,
1299    }
1300
1301    impl ConcreteMessage for MsgEd25519SignatureDepA {
1302        const MESSAGE_TYPE: u16 = 3073;
1303        const MESSAGE_NAME: &'static str = "MSG_ED25519_SIGNATURE_DEP_A";
1304    }
1305
1306    impl SbpMessage for MsgEd25519SignatureDepA {
1307        fn message_name(&self) -> &'static str {
1308            <Self as ConcreteMessage>::MESSAGE_NAME
1309        }
1310        fn message_type(&self) -> Option<u16> {
1311            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
1312        }
1313        fn sender_id(&self) -> Option<u16> {
1314            self.sender_id
1315        }
1316        fn set_sender_id(&mut self, new_id: u16) {
1317            self.sender_id = Some(new_id);
1318        }
1319        fn encoded_len(&self) -> usize {
1320            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
1321        }
1322        fn is_valid(&self) -> bool {
1323            true
1324        }
1325        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
1326            Ok(self)
1327        }
1328    }
1329
1330    impl FriendlyName for MsgEd25519SignatureDepA {
1331        fn friendly_name() -> &'static str {
1332            "ED25519 SIGNATURE DEP A"
1333        }
1334    }
1335
1336    impl TryFrom<Sbp> for MsgEd25519SignatureDepA {
1337        type Error = TryFromSbpError;
1338        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
1339            match msg {
1340                Sbp::MsgEd25519SignatureDepA(m) => Ok(m),
1341                _ => Err(TryFromSbpError(msg)),
1342            }
1343        }
1344    }
1345
1346    impl WireFormat for MsgEd25519SignatureDepA {
1347        const MIN_LEN: usize = <[u8; 64] as WireFormat>::MIN_LEN
1348            + <[u8; 20] as WireFormat>::MIN_LEN
1349            + <Vec<u32> as WireFormat>::MIN_LEN;
1350        fn len(&self) -> usize {
1351            WireFormat::len(&self.signature)
1352                + WireFormat::len(&self.fingerprint)
1353                + WireFormat::len(&self.signed_messages)
1354        }
1355        fn write<B: BufMut>(&self, buf: &mut B) {
1356            WireFormat::write(&self.signature, buf);
1357            WireFormat::write(&self.fingerprint, buf);
1358            WireFormat::write(&self.signed_messages, buf);
1359        }
1360        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
1361            MsgEd25519SignatureDepA {
1362                sender_id: None,
1363                signature: WireFormat::parse_unchecked(buf),
1364                fingerprint: WireFormat::parse_unchecked(buf),
1365                signed_messages: WireFormat::parse_unchecked(buf),
1366            }
1367        }
1368    }
1369}
1370
1371pub mod msg_ed25519_signature_dep_b {
1372    #![allow(unused_imports)]
1373
1374    use super::*;
1375    use crate::messages::lib::*;
1376
1377    /// Deprecated
1378    ///
1379    /// Deprecated.
1380    ///
1381    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1382    #[allow(clippy::derive_partial_eq_without_eq)]
1383    #[derive(Debug, PartialEq, Clone)]
1384    pub struct MsgEd25519SignatureDepB {
1385        /// The message sender_id
1386        #[cfg_attr(feature = "serde", serde(skip_serializing, alias = "sender"))]
1387        pub sender_id: Option<u16>,
1388        /// Signature message counter. Zero indexed and incremented with each
1389        /// signature message.  The counter will not increment if this message was
1390        /// in response to an on demand request.  The counter will roll over after
1391        /// 256 messages. Upon connection, the value of the counter may not
1392        /// initially be zero.
1393        #[cfg_attr(feature = "serde", serde(rename = "stream_counter"))]
1394        pub stream_counter: u8,
1395        /// On demand message counter. Zero indexed and incremented with each
1396        /// signature message sent in response to an on demand message. The counter
1397        /// will roll over after 256 messages.  Upon connection, the value of the
1398        /// counter may not initially be zero.
1399        #[cfg_attr(feature = "serde", serde(rename = "on_demand_counter"))]
1400        pub on_demand_counter: u8,
1401        /// ED25519 signature for messages.
1402        #[cfg_attr(feature = "serde", serde(with = "BigArray", rename = "signature"))]
1403        pub signature: [u8; 64],
1404        /// SHA-1 fingerprint of the associated certificate.
1405        #[cfg_attr(feature = "serde", serde(rename = "fingerprint"))]
1406        pub fingerprint: [u8; 20],
1407        /// CRCs of signed messages.
1408        #[cfg_attr(feature = "serde", serde(rename = "signed_messages"))]
1409        pub signed_messages: Vec<u32>,
1410    }
1411
1412    impl ConcreteMessage for MsgEd25519SignatureDepB {
1413        const MESSAGE_TYPE: u16 = 3075;
1414        const MESSAGE_NAME: &'static str = "MSG_ED25519_SIGNATURE_DEP_B";
1415    }
1416
1417    impl SbpMessage for MsgEd25519SignatureDepB {
1418        fn message_name(&self) -> &'static str {
1419            <Self as ConcreteMessage>::MESSAGE_NAME
1420        }
1421        fn message_type(&self) -> Option<u16> {
1422            Some(<Self as ConcreteMessage>::MESSAGE_TYPE)
1423        }
1424        fn sender_id(&self) -> Option<u16> {
1425            self.sender_id
1426        }
1427        fn set_sender_id(&mut self, new_id: u16) {
1428            self.sender_id = Some(new_id);
1429        }
1430        fn encoded_len(&self) -> usize {
1431            WireFormat::len(self) + crate::HEADER_LEN + crate::CRC_LEN
1432        }
1433        fn is_valid(&self) -> bool {
1434            true
1435        }
1436        fn into_valid_msg(self) -> Result<Self, crate::messages::invalid::Invalid> {
1437            Ok(self)
1438        }
1439    }
1440
1441    impl FriendlyName for MsgEd25519SignatureDepB {
1442        fn friendly_name() -> &'static str {
1443            "ED25519 SIGNATURE DEP B"
1444        }
1445    }
1446
1447    impl TryFrom<Sbp> for MsgEd25519SignatureDepB {
1448        type Error = TryFromSbpError;
1449        fn try_from(msg: Sbp) -> Result<Self, Self::Error> {
1450            match msg {
1451                Sbp::MsgEd25519SignatureDepB(m) => Ok(m),
1452                _ => Err(TryFromSbpError(msg)),
1453            }
1454        }
1455    }
1456
1457    impl WireFormat for MsgEd25519SignatureDepB {
1458        const MIN_LEN: usize = <u8 as WireFormat>::MIN_LEN
1459            + <u8 as WireFormat>::MIN_LEN
1460            + <[u8; 64] as WireFormat>::MIN_LEN
1461            + <[u8; 20] as WireFormat>::MIN_LEN
1462            + <Vec<u32> as WireFormat>::MIN_LEN;
1463        fn len(&self) -> usize {
1464            WireFormat::len(&self.stream_counter)
1465                + WireFormat::len(&self.on_demand_counter)
1466                + WireFormat::len(&self.signature)
1467                + WireFormat::len(&self.fingerprint)
1468                + WireFormat::len(&self.signed_messages)
1469        }
1470        fn write<B: BufMut>(&self, buf: &mut B) {
1471            WireFormat::write(&self.stream_counter, buf);
1472            WireFormat::write(&self.on_demand_counter, buf);
1473            WireFormat::write(&self.signature, buf);
1474            WireFormat::write(&self.fingerprint, buf);
1475            WireFormat::write(&self.signed_messages, buf);
1476        }
1477        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
1478            MsgEd25519SignatureDepB {
1479                sender_id: None,
1480                stream_counter: WireFormat::parse_unchecked(buf),
1481                on_demand_counter: WireFormat::parse_unchecked(buf),
1482                signature: WireFormat::parse_unchecked(buf),
1483                fingerprint: WireFormat::parse_unchecked(buf),
1484                signed_messages: WireFormat::parse_unchecked(buf),
1485            }
1486        }
1487    }
1488}
1489
1490pub mod utc_time {
1491    #![allow(unused_imports)]
1492
1493    use super::*;
1494    use crate::messages::lib::*;
1495    /// UTC Time
1496    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1497    #[allow(clippy::derive_partial_eq_without_eq)]
1498    #[derive(Debug, PartialEq, Clone)]
1499    pub struct UtcTime {
1500        /// Year
1501        #[cfg_attr(feature = "serde", serde(rename = "year"))]
1502        pub year: u16,
1503        /// Month (range 1 .. 12)
1504        #[cfg_attr(feature = "serde", serde(rename = "month"))]
1505        pub month: u8,
1506        /// days in the month (range 1-31)
1507        #[cfg_attr(feature = "serde", serde(rename = "day"))]
1508        pub day: u8,
1509        /// hours of day (range 0-23)
1510        #[cfg_attr(feature = "serde", serde(rename = "hours"))]
1511        pub hours: u8,
1512        /// minutes of hour (range 0-59)
1513        #[cfg_attr(feature = "serde", serde(rename = "minutes"))]
1514        pub minutes: u8,
1515        /// seconds of minute (range 0-60) rounded down
1516        #[cfg_attr(feature = "serde", serde(rename = "seconds"))]
1517        pub seconds: u8,
1518        /// nanoseconds of second (range 0-999999999)
1519        #[cfg_attr(feature = "serde", serde(rename = "ns"))]
1520        pub ns: u32,
1521    }
1522
1523    impl WireFormat for UtcTime {
1524        const MIN_LEN: usize = <u16 as WireFormat>::MIN_LEN
1525            + <u8 as WireFormat>::MIN_LEN
1526            + <u8 as WireFormat>::MIN_LEN
1527            + <u8 as WireFormat>::MIN_LEN
1528            + <u8 as WireFormat>::MIN_LEN
1529            + <u8 as WireFormat>::MIN_LEN
1530            + <u32 as WireFormat>::MIN_LEN;
1531        fn len(&self) -> usize {
1532            WireFormat::len(&self.year)
1533                + WireFormat::len(&self.month)
1534                + WireFormat::len(&self.day)
1535                + WireFormat::len(&self.hours)
1536                + WireFormat::len(&self.minutes)
1537                + WireFormat::len(&self.seconds)
1538                + WireFormat::len(&self.ns)
1539        }
1540        fn write<B: BufMut>(&self, buf: &mut B) {
1541            WireFormat::write(&self.year, buf);
1542            WireFormat::write(&self.month, buf);
1543            WireFormat::write(&self.day, buf);
1544            WireFormat::write(&self.hours, buf);
1545            WireFormat::write(&self.minutes, buf);
1546            WireFormat::write(&self.seconds, buf);
1547            WireFormat::write(&self.ns, buf);
1548        }
1549        fn parse_unchecked<B: Buf>(buf: &mut B) -> Self {
1550            UtcTime {
1551                year: WireFormat::parse_unchecked(buf),
1552                month: WireFormat::parse_unchecked(buf),
1553                day: WireFormat::parse_unchecked(buf),
1554                hours: WireFormat::parse_unchecked(buf),
1555                minutes: WireFormat::parse_unchecked(buf),
1556                seconds: WireFormat::parse_unchecked(buf),
1557                ns: WireFormat::parse_unchecked(buf),
1558            }
1559        }
1560    }
1561}