coset 0.4.2

Set of types for supporting COSE
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
// Copyright 2021 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
////////////////////////////////////////////////////////////////////////////////

//! Enumerations for IANA-managed values.
//!
//! Sources:
//! - <https://www.iana.org/assignments/cose/cose.xhtml>
//! - <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml>
//! - <https://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats>
//! - <https://www.iana.org/assignments/cwt/cwt.xhtml>

#[cfg(test)]
mod tests;

/// Trait indicating an enum that can be constructed from `i64` values.
pub trait EnumI64: Sized + Eq {
    fn from_i64(i: i64) -> Option<Self>;
    fn to_i64(&self) -> i64;
}

/// Trait indicating an enum with a range of private values.
pub trait WithPrivateRange {
    fn is_private(i: i64) -> bool;
}

/// Generate an enum with associated values, plus a `from_i64` method.
macro_rules! iana_registry {
    ( $(#[$attr:meta])* $enum_name:ident {$($(#[$fattr:meta])* $name:ident: $val:expr,)* } ) => {
        #[allow(non_camel_case_types)]
        $(#[$attr])*
        #[non_exhaustive]
        #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
        pub enum $enum_name {
            $($(#[$fattr])* $name = $val,)*
        }
        impl EnumI64 for $enum_name {
            fn from_i64(i: i64) -> Option<Self> {
                match i {
                    $(x if x == Self::$name as i64 => Some(Self::$name),)*
                    _ => None,
                }
            }
            #[inline]
            fn to_i64(&self) -> i64 {
                *self as i64
            }
        }
    }
}

iana_registry! {
    /// IANA-registered COSE header parameters.
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#header-parameters>
    /// as of 2025-09-13.
    HeaderParameter {
        /// Reserved
        Reserved: 0,
        /// Cryptographic algorithm to use
        ///
        /// Associated value of type int / tstr
        Alg: 1,
        /// Critical headers to be understood
        ///
        /// Associated value of type [+ label]
        Crit: 2,
        /// Content type of the payload
        ///
        /// Associated value of type tstr / uint
        ContentType: 3,
        /// Key identifier
        ///
        /// Associated value of type bstr
        Kid: 4,
        /// Full Initialization Vector
        ///
        /// Associated value of type bstr
        Iv: 5,
        /// Partial Initialization Vector
        ///
        /// Associated value of type bstr
        PartialIv: 6,
        /// CBOR-encoded signature structure
        ///
        /// Associated value of type COSE_Signature / [+ COSE_Signature ]
        CounterSignature: 7,
        /// Counter signature with implied signer and headers
        ///
        /// Associated value of type bstr
        CounterSignature0: 9,
        /// Identifies the context for the key identifier
        ///
        /// Associated value of type bstr
        KidContext: 10,
        /// Counter signature v2
        ///
        /// Associated value of type COSE_Countersignature / [+ COSE_Countersignature]
        CounterSignatureV2: 11,
        /// Abbreviated counter signature v2.
        ///
        /// Associated value of type COSE_Countersignature0
        CounterSignature0V2: 12,
        /// CWT containing a COSE_Key in a cnf claim
        ///
        /// Associated value of type COSE_Messages
        KeyCwt: 13,
        /// CWT Claims set containing a COSE_Key in a cnf claim
        ///
        /// Associated value of type map
        KeyCwtClaimsSet: 14,
        /// CWT Claims
        ///
        /// Associated value of type map
        CwtClaims: 15,
        /// Content type of complete COSE object.
        ///
        /// Associated value of type uint/tstr
        ObjectContentType: 16,
        /// An unordered bag of X.509 certificates
        ///
        /// Associated value of type COSE_X509
        X5Bag: 32,
        /// An ordered chain of X.509 certificates
        ///
        /// Associated value of type COSE_X509
        X5Chain: 33,
        /// Hash of an X.509 certificate
        ///
        /// Associated value of type COSE_CertHash
        X5T: 34,
        /// URI pointing to an X.509 certificate
        ///
        /// Associated value of type uri
        X5U: 35,
        /// Challenge Nonce
        ///
        /// Associated value of type bstr
        CuphNonce: 256,
        /// Public Key
        ///
        /// Associated value of type array
        CuphOwnerPubKey: 257,
    }
}

/// Integer values for COSE header parameters below this value are reserved for private use.
pub const HEADER_PARAMETER_PRIVATE_USE_MAX: i64 = -65536;

impl WithPrivateRange for HeaderParameter {
    fn is_private(i: i64) -> bool {
        i < HEADER_PARAMETER_PRIVATE_USE_MAX
    }
}

iana_registry! {
    /// IANA-registered COSE header algorithm parameters.
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#header-algorithm-parameters>
    /// as of 2025-09-13.
    HeaderAlgorithmParameter {
        /// Static key X.509 certificate chain
        ///
        /// Associated value of type COSE_X509
        X5ChainSender: -29,
        /// URI for the sender's X.509 certificate
        ///
        /// Associated value of type uri
        X5USender: -28,
        /// Thumbprint for the sender's X.509 certificate
        ///
        /// Associated value of type COSE_CertHash
        X5TSender: -27,
        /// Party V other provided information
        ///
        /// Associated value of type bstr
        PartyVOther: -26,
        /// Party V provided nonce
        ///
        /// Associated value of type bstr / int
        PartyVNonce: -25,
        /// Party V identity information
        ///
        /// Associated value of type bstr
        PartyVIdentity: -24,
        /// Party U other provided information
        ///
        /// Associated value of type bstr
        PartyUOther: -23,
        /// Party U provided nonce
        ///
        /// Associated value of type bstr / int
        PartyUNonce: -22,
        /// Party U identity information
        ///
        /// Associated value of type bstr
        PartyUIdentity: -21,
        /// Random salt
        ///
        /// Associated value of type bstr
        Salt: -20,
        /// Static public key identifier for the sender
        ///
        /// Associated value of type bstr
        StaticKeyId: -3,
        /// Static public key for the sender
        ///
        /// Associated value of type COSE_Key
        StaticKey: -2,
        /// Ephemeral public key for the sender
        ///
        /// Associated value of type COSE_Key
        EphemeralKey: -1,
    }
}

iana_registry! {
    /// IANA-registered COSE algorithms.
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#algorithms>
    /// as of 2025-11-06.
    Algorithm {
        /// RSASSA-PKCS1-v1_5 using SHA-1 (deprecated)
        RS1: -65535,
        /// AES-CTR with 128-bit key (deprecated)
        AesCtr128: -65534,
        /// AES-CTR with 192-bit key (deprecated)
        AesCtr192: -65533,
        /// AES-CTR with 256-bit key (deprecated)
        AesCtr256: -65532,
        /// AES-CBC with 128-bit key (deprecated)
        AesCbc128: -65531,
        /// AES-CBC with 192-bit key (deprecated)
        AesCbc192: -65530,
        /// AES-CBC with 256-bit key (deprecated)
        AesCbc256: -65529,
        /// ECDSA using BrainpoolP512r1 curve and SHA-512
        ESB512: -268,
        /// ECDSA using BrainpoolP384r1 curve and SHA-384
        ESB384: -267,
        /// ECDSA using BrainpoolP320r1 curve and SHA-384
        ESB320: -266,
        /// ECDSA using BrainpoolP256r1 curve and SHA-256
        ESB256: -265,
        /// WalnutDSA signature
        WalnutDSA: -260,
        /// RSASSA-PKCS1-v1_5 using SHA-512
        RS512: -259,
        /// RSASSA-PKCS1-v1_5 using SHA-384
        RS384: -258,
        /// RSASSA-PKCS1-v1_5 using SHA-256
        RS256: -257,
        /// EdDSA using the Ed448 parameter set in Section 5.2 of RFC8032
        Ed448: -53,
        /// ECDSA using P-521 curve and SHA-512
        ESP512: -52,
        /// ECDSA using P-384 curve and SHA-384
        ESP384: -51,
        /// ML-DSA-87
        ML_DSA_87: -50,
        /// ML-DSA-65
        ML_DSA_65: -49,
        /// ML-DSA-44
        ML_DSA_44: -48,
        /// ECDSA using secp256k1 curve and SHA-256
        ES256K: -47,
        /// HSS/LMS hash-based digital signature
        HSS_LMS: -46,
        /// SHAKE-256 512-bit Hash Value
        SHAKE256: -45,
        /// SHA-2 512-bit Hash
        SHA_512: -44,
        /// SHA-2 384-bit Hash
        SHA_384: -43,
        /// RSAES-OAEP w/ SHA-512
        RSAES_OAEP_SHA_512: -42,
        /// RSAES-OAEP w/ SHA-256
        RSAES_OAEP_SHA_256: -41,
        /// RSAES-OAEP w/ SHA-1
        RSAES_OAEP_RFC_8017_default: -40,
        /// RSASSA-PSS w/ SHA-512
        PS512: -39,
        /// RSASSA-PSS_SHA-384
        PS384: -38,
        /// RSASSA-PSS w/ SHA-256
        PS256: -37,
        /// ECDSA w/ SHA-512 (deprecated)
        ES512: -36,
        /// ECDSA w/ SHA-384 (deprecated)
        ES384: -35,
        /// ECDH SS w/ Concat KDF and AES Key Wrap w/ 256-bit key
        ECDH_SS_A256KW: -34,
        /// ECDH SS w/ Concat KDF and AES Key Wrap w/ 192-bit key
        ECDH_SS_A192KW: -33,
        /// ECDH SS w/ Concat KDF and AES Key Wrap w/ 128-bit key
        ECDH_SS_A128KW: -32,
        /// ECDH ES w/ Concat KDF and AES Key Wrap w/ 256-bit key
        ECDH_ES_A256KW: -31,
        /// ECDH ES w/ Concat KDF and AES Key Wrap w/ 192-bit key
        ECDH_ES_A192KW: -30,
        /// ECDH ES w/ Concat KDF and AES Key Wrap w/ 128-bit key
        ECDH_ES_A128KW: -29,
        /// ECDH SS w/ HKDF - generate key directly
        ECDH_SS_HKDF_512: -28,
        /// ECDH SS w/ HKDF - generate key directly
        ECDH_SS_HKDF_256: -27,
        /// ECDH ES w/ HKDF - generate key directly
        ECDH_ES_HKDF_512: -26,
        /// ECDH ES w/ HKDF - generate key directly
        ECDH_ES_HKDF_256: -25,
        /// EdDSA using the Ed25519 parameter set in Section 5.1 of RFC8032
        Ed25519: -19,
        /// SHAKE-128 256-bit Hash Value
        SHAKE128: -18,
        /// SHA-2 512-bit Hash truncated to 256-bits
        SHA_512_256: -17,
        /// SHA-2 256-bit Hash
        SHA_256: -16,
        /// SHA-2 256-bit Hash truncated to 64-bits
        SHA_256_64: -15,
        /// SHA-1 Hash
        SHA_1: -14,
        /// Shared secret w/ AES-MAC 256-bit key
        Direct_HKDF_AES_256: -13,
        /// Shared secret w/ AES-MAC 128-bit key
        Direct_HKDF_AES_128: -12,
        /// Shared secret w/ HKDF and SHA-512
        Direct_HKDF_SHA_512: -11,
        /// Shared secret w/ HKDF and SHA-256
        Direct_HKDF_SHA_256: -10,
        /// ECDSA using P-256 curve and SHA-256
        ESP256: -9,
        /// EdDSA (deprecated)
        EdDSA: -8,
        /// ECDSA w/ SHA-256 (deprecated)
        ES256: -7,
        /// Direct use of CEK
        Direct: -6,
        /// AES Key Wrap w/ 256-bit key
        A256KW: -5,
        /// AES Key Wrap w/ 192-bit key
        A192KW: -4,
        /// AES Key Wrap w/ 128-bit key
        A128KW: -3,
        /// Reserved
        Reserved: 0,
        /// AES-GCM mode w/ 128-bit key, 128-bit tag
        A128GCM: 1,
        /// AES-GCM mode w/ 192-bit key, 128-bit tag
        A192GCM: 2,
        /// AES-GCM mode w/ 256-bit key, 128-bit tag
        A256GCM: 3,
        /// HMAC w/ SHA-256 truncated to 64 bits
        HMAC_256_64: 4,
        /// HMAC w/ SHA-256
        HMAC_256_256: 5,
        /// HMAC w/ SHA-384
        HMAC_384_384: 6,
        /// HMAC w/ SHA-512
        HMAC_512_512: 7,
        /// AES-CCM mode 128-bit key, 64-bit tag, 13-byte nonce
        AES_CCM_16_64_128: 10,
        /// AES-CCM mode 256-bit key, 64-bit tag, 13-byte nonce
        AES_CCM_16_64_256: 11,
        /// AES-CCM mode 128-bit key, 64-bit tag, 7-byte nonce
        AES_CCM_64_64_128: 12,
        /// AES-CCM mode 256-bit key, 64-bit tag, 7-byte nonce
        AES_CCM_64_64_256: 13,
        /// AES-MAC 128-bit key, 64-bit tag
        AES_MAC_128_64: 14,
        /// AES-MAC 256-bit key, 64-bit tag
        AES_MAC_256_64: 15,
        /// ChaCha20/Poly1305 w/ 256-bit key, 128-bit tag
        ChaCha20Poly1305: 24,
        /// AES-MAC 128-bit key, 128-bit tag
        AES_MAC_128_128: 25,
        /// AES-MAC 256-bit key, 128-bit tag
        AES_MAC_256_128: 26,
        /// AES-CCM mode 128-bit key, 128-bit tag, 13-byte nonce
        AES_CCM_16_128_128: 30,
        /// AES-CCM mode 256-bit key, 128-bit tag, 13-byte nonce
        AES_CCM_16_128_256: 31,
        /// AES-CCM mode 128-bit key, 128-bit tag, 7-byte nonce
        AES_CCM_64_128_128: 32,
        /// AES-CCM mode 256-bit key, 128-bit tag, 7-byte nonce
        AES_CCM_64_128_256: 33,
        /// For doing IV generation for symmetric algorithms.
        IV_GENERATION: 34,
    }
}

/// Integer values for COSE algorithms below this value are reserved for private use.
pub const ALGORITHM_PRIVATE_USE_MAX: i64 = -65536;

impl WithPrivateRange for Algorithm {
    fn is_private(i: i64) -> bool {
        i < ALGORITHM_PRIVATE_USE_MAX
    }
}

iana_registry! {
    /// IANA-registered COSE common key parameters.
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#key-common-parameters>
    /// as of 2025-09-13.
    KeyParameter {
        /// Reserved value.
        Reserved: 0,
        /// Identification of the key type
        ///
        /// Associated value of type tstr / int
        Kty: 1,
        /// Key identification value - match to kid in message
        ///
        /// Associated value of type bstr
        Kid: 2,
        /// Key usage restriction to this algorithm
        ///
        /// Associated value of type tstr / int
        Alg: 3,
        /// Restrict set of permissible operations
        ///
        /// Associated value of type [+ (tstr / int)]
        KeyOps: 4,
        /// Base IV to be XORed with Partial IVs
        ///
        /// Associated value of type bstr
        BaseIv: 5,
    }
}

iana_registry! {
    /// IANA-registered COSE key parameters for keys of type [`KeyType::OKP`].
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#key-type-parameters>
    /// as of 2025-09-13.
    OkpKeyParameter {
        /// EC identifier - Taken from the "COSE Elliptic Curves" registry
        ///
        /// Associated value of type tstr / int
        Crv: -1,
        /// x-coordinate
        ///
        /// Associated value of type bstr
        X: -2,
        /// Private key
        ///
        /// Associated value of type bstr
        D: -4,
    }
}

iana_registry! {
    /// IANA-registered COSE key parameters for keys of type [`KeyType::EC2`].
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#key-type-parameters>
    /// as of 2025-09-13.
    Ec2KeyParameter {
        /// EC identifier - Taken from the "COSE Elliptic Curves" registry
        ///
        /// Associated value of type tstr / int
        Crv: -1,
        /// Public Key
        ///
        /// Associated value of type bstr
        X: -2,
        /// y-coordinate
        ///
        /// Associated value of type bstr / bool
        Y: -3,
        /// Private key
        ///
        /// Associated value of type bstr
        D: -4,
    }
}

iana_registry! {
    /// IANA-registered COSE key parameters for keys of type [`KeyType::RSA`].
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#key-type-parameters>
    /// as of 2025-09-13.
    RsaKeyParameter {
        /// The RSA modulus n
        ///
        /// Associated value of type bstr
        N: -1,
        /// The RSA public exponent e
        ///
        /// Associated value of type bstr
        E: -2,
        /// The RSA private exponent d
        ///
        /// Associated value of type bstr
        D: -3,
        /// The prime factor p of n
        ///
        /// Associated value of type bstr
        P: -4,
        /// The prime factor q of n
        ///
        /// Associated value of type bstr
        Q: -5,
        /// dP is d mod (p - 1)
        ///
        /// Associated value of type bstr
        DP: -6,
        /// dQ is d mod (q - 1)
        ///
        /// Associated value of type bstr
        DQ: -7,
        /// qInv is the CRT coefficient q^(-1) mod p
        ///
        /// Associated value of type bstr
        QInv: -8,
        /// Other prime infos, an array
        ///
        /// Associated value of type array
        Other: -9,
        /// a prime factor r_i of n, where i >= 3
        ///
        /// Associated value of type bstr
        RI: -10,
        /// d_i = d mod (r_i - 1)
        ///
        /// Associated value of type bstr
        DI: -11,
        /// The CRT coefficient t_i = (r_1 * r_2 * ... * r_(i-1))^(-1) mod r_i
        ///
        /// Associated value of type bstr
        TI: -12,
    }
}

iana_registry! {
    /// IANA-registered COSE key parameters for keys of type [`KeyType::Symmetric`].
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#key-type-parameters>
    /// as of 2025-09-13.
    SymmetricKeyParameter {
        /// Key Value
        ///
        /// Associated value of type bstr
        K: -1,
    }
}

iana_registry! {
    /// IANA-registered COSE key parameters for keys of type [`KeyType::HSS_LMS`].
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#key-type-parameters>
    /// as of 2025-09-13.
    HssLmsKeyParameter {
        /// Public key for HSS/LMS hash-based digital signature
        ///
        /// Associated value of type bstr
        Pub: -1,
    }
}

iana_registry! {
    /// IANA-registered COSE key parameters for keys of type [`KeyType::WalnutDSA`].
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#key-type-parameters>
    /// as of 2025-09-13.
    WalnutDsaKeyParameter {
        /// Group and Matrix (NxN) size
        ///
        /// Associated value of type uint
        N: -1,
        /// Finite field F_q
        ///
        /// Associated value of type uint
        Q: -2,
        /// List of T-values, enties in F_q
        ///
        /// Associated value of type array of uint
        TValues: -3,
        /// NxN Matrix of enties in F_q in column-major form
        ///
        /// Associated value of type array of array of uint
        Matrix1: -4,
        /// Permutation associated with matrix 1
        ///
        /// Associated value of type array of uint
        Permutation1: -5,
        /// NxN Matrix of enties in F_q in column-major form
        ///
        /// Associated value of type array of array of uint
        Matrix2: -6,
    }
}

iana_registry! {
    /// IANA-registered COSE key parameters for keys of type [`KeyType::AKP`].
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#key-type-parameters>
    /// as of 2025-09-13.
    AkpKeyParameter {
        /// Public key
        Pub: -1,
        /// Private key
        Priv: -2,
    }
}

iana_registry! {
    /// IANA-registered COSE key types.
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#key-type>
    /// as of 2025-09-13.
    KeyType {
        /// This value is reserved
        Reserved: 0,
        /// Octet Key Pair
        OKP: 1,
        /// Elliptic Curve Keys w/ x- and y-coordinate pair
        EC2: 2,
        /// RSA Key
        RSA: 3,
        /// Symmetric Keys
        Symmetric: 4,
        /// Public key for HSS/LMS hash-based digital signature
        HSS_LMS: 5,
        /// WalnutDSA public key
        WalnutDSA: 6,
        /// Algorithm Key Pair
        AKP: 7,
    }
}

iana_registry! {
    /// IANA-registered COSE elliptic curves.
    ///
    /// From IANA registry <https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves>
    /// as of 2025-09-13.
    EllipticCurve {
        Reserved: 0,
        /// EC2: NIST P-256 also known as secp256r1
        P_256: 1,
        /// EC2: NIST P-384 also known as secp384r1
        P_384: 2,
        /// EC2: NIST P-521 also known as secp521r1
        P_521: 3,
        /// OKP: X25519 for use w/ ECDH only
        X25519: 4,
        /// OKP: X448 for use w/ ECDH only
        X448: 5,
        /// OKP: Ed25519 for use w/ EdDSA only
        Ed25519: 6,
        /// OKP: Ed448 for use w/ EdDSA only
        Ed448: 7,
        /// EC2: SECG secp256k1 curve
        Secp256k1: 8,
        /// BrainpoolP256r1
        BrainpoolP256R1: 256,
        /// BrainpoolP320r1
        BrainpoolP320R1: 257,
        /// BrainpoolP384r1
        BrainpoolP384R1: 258,
        /// BraingpoolP512r1
        BrainpoolP512R1: 259,
    }
}

/// Integer values for COSE elliptic curves below this value are reserved for private use.
pub const ELLIPTIC_CURVE_PRIVATE_USE_MAX: i64 = -65536;

impl WithPrivateRange for EllipticCurve {
    fn is_private(i: i64) -> bool {
        i < ELLIPTIC_CURVE_PRIVATE_USE_MAX
    }
}

iana_registry! {
    /// Key operation values.
    ///
    /// See RFC 8152 section 7.1 table 4.
    KeyOperation {
        /// Key is used to create signatures. Requires private key fields.
        Sign: 1,
        /// Key is used for verification of signatures.
        Verify: 2,
        /// Key is used for key transport encryption.
        Encrypt: 3,
        /// Key is used for key transport decryption. Requires private key fields.
        Decrypt: 4,
        /// Key is used for key wrap encryption.
        WrapKey: 5,
        /// Key is used for key wrap decryption.  Requires private key fields.
        UnwrapKey: 6,
        /// Key is used for deriving keys.  Requires private key fields.
        DeriveKey: 7,
        /// Key is used for deriving bits not to be used as a key.  Requires private key fields.
        DeriveBits: 8,
        /// Key is used for creating MACs.
        MacCreate: 9,
        /// Key is used for validating MACs.
        MacVerify: 10,
    }
}

iana_registry! {
    /// CBOR tag values for COSE structures.
    ///
    /// From IANA registry <https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml>
    /// as of 2025-09-13.
    CborTag {
        /// COSE Single Recipient Encrypted Data Object
        CoseEncrypt0: 16,
        /// COSE Mac w/o Recipients Object
        CoseMac0: 17,
        /// COSE Single Signer Data Object
        CoseSign1: 18,
        /// COSE standalone V2 countersignature
        CoseCountersignature: 19,
        /// CBOR Web Token (CWT)
        Cwt: 61,
        /// COSE Encrypted Data Object
        CoseEncrypt: 96,
        /// COSE MACed Data Object
        CoseMac: 97,
        /// COSE Signed Data Object
        CoseSign: 98,
    }
}

iana_registry! {
    /// CoAP Content Formats
    ///
    /// From IANA registry <https://www.iana.org/assignments/core-parameters/core-parameters.xhtml#content-formats>
    /// as of 2025-09-13.
    CoapContentFormat {
        /// text/plain; charset=utf-8
        TextPlainUtf8: 0,
        /// application/cose; cose-type="cose-encrypt0"
        CoseEncrypt0: 16,
        /// application/cose; cose-type="cose-mac0"
        CoseMac0: 17,
        /// application/cose; cose-type="cose-sign1"
        CoseSign1: 18,
        /// application/ace+cbor
        AceCbor: 19,
        /// image/gif
        ImageGif: 21,
        /// image/jpeg
        ImageJpeg: 22,
        /// image/png
        ImagePng: 23,
        /// application/link-format
        LinkFormat: 40,
        /// application/xml
        Xml: 41,
        /// application/octet-stream
        OctetStream: 42,
        /// application/exi
        Exi: 47,
        /// application/json
        Json: 50,
        /// application/json-patch+json
        JsonPatchJson: 51,
        /// application/merge-patch+json
        MergePatchJson: 52,
        /// application/cbor
        Cbor: 60,
        /// application/cwt
        Cwt: 61,
        /// application/multipart-core
        MultipartCore: 62,
        /// application/cbor-seq
        CborSeq: 63,
        /// application/edhoc+cbor-seq
        EdhocCborSeq: 64,
        /// application/cid-edhoc+cbor-seq
        CidEdhocCborSeq: 65,
        /// application/cose; cose-type="cose-encrypt"
        CoseEncrypt: 96,
        /// application/cose; cose-type="cose-mac"
        CoseMac: 97,
        /// application/cose; cose-type="cose-sign"
        CoseSign: 98,
        /// application/cose-key
        CoseKey: 101,
        /// application/cose-key-set
        CoseKeySet: 102,
        /// application/senml+json
        SenmlJson: 110,
        /// application/sensml+json
        SensmlJson: 111,
        /// application/senml+cbor
        SenmlCbor: 112,
        /// application/sensml+cbor
        SensmlCbor: 113,
        /// application/senml-exi
        SenmlExi: 114,
        /// application/sensml-exi
        SensmlExi: 115,
        /// application/yang-data+cbor
        YangData: 140,
        /// application/coap-group+json
        CoapGroupJson: 256,
        /// application/concise-problem-details+cbor
        ConciseProblemDetailsCbor: 257,
        /// application/swid+cbor
        SwidCbor:258,
        /// application/pkixcmp
        PkixCmp: 259,
        /// application/yang-sid+json
        YangSidJson: 260,
        /// application/ace-groupcomm+cbor
        AceGroupcommCbor: 261,
        /// application/ace-trl+cbor
        AceTrlCbor: 262,
        /// application/eat+cwt
        EatCwt: 263,
        /// application/eat+jwt
        EatJwt: 264,
        /// application/eat-bun+cbor
        EatBunCbor: 265,
        /// application/eat-bun+json
        EatBunJson: 266,
        /// application/eat-ucs+cbor
        EatUcsCbor: 267,
        /// application/eat-ucs+json
        EatUcsJson: 268,
        /// application/dots+cbor
        DotsCbor: 271,
        /// application/missing-blocks+cbor-seq
        MissingBlocksCborSeq: 272,
        /// application/pkcs7-mime; smime-type=server-generated-key
        Pkcs7MimeSmimeTypeServerGeneratedKey: 280,
        /// application/pkcs7-mime; smime-type=certs-only
        Pkcs7MimeSmimeTypeCertsOnly: 281,
        /// application/pkcs7-mime; smime-type=CMC-Request
        Pkcs7MimeSmimeTypeCmcRequest: 282,
        /// application/pkcs7-mime; smime-type=CMC-Response
        Pkcs7MimeSmimeTypeCmcResponse: 283,
        /// application/pkcs8
        Pkcs8: 284,
        /// application/csrattrs
        Csrattrs: 285,
        /// application/pkcs10
        Pkcs10: 286,
        /// application/pkix-cert
        PkixCert: 287,
        /// application/aif+cbor
        AifCbor: 290,
        /// application/aif+json
        AifJson: 291,
        /// application/senml+xml
        SenmlXml: 310,
        /// application/sensml+xml
        SensmlXml: 311,
        /// application/senml-etch+json
        SenmlEtchJson: 320,
        /// application/senml-etch+cbor
        SenmlEtchCbor: 322,
        /// application/yang-data+cbor
        YangDataCbor: 340,
        /// application/yang-data+cbor; id=name
        YangDataCborName: 341,
        /// application/td+json
        TdJson: 432,
        /// application/tm+json
        TmJson: 433,
        /// application/uccs+cbor
        UccsCbor: 601,
        /// application/vnd.ocf+cbor
        VndOcfCbor: 10000,
        /// application/oscore
        Oscore: 10001,
        /// application/javascript
        Javascript: 10002,
        /// application/eat+cwt
        EatCwtTfm: 10003,
        /// application/eat+cwt
        EatCwtLegacy: 10004,
        /// application/json deflate
        JsonDeflate: 11050,
        /// application/cbor deflate
        CborDeflate: 11060,
        /// application/vnd.oma.lwm2m+tlv
        VndOmaLwm2mTlv: 11542,
        /// application/vnd.oma.lwm2m+json
        VndOmaLwm2mJson: 11543,
        /// application/vnd.oma.lwm2m+cbor
        VndOmaLwm2mCbor: 11544,
        /// text/css
        TextCss: 20000,
        /// image/svg+xml
        ImageSvgXml: 30000,
    }
}

iana_registry! {
    /// CBOR Web Token (CWT) Claims
    /// From IANA registry <https://www.iana.org/assignments/cwt/cwt.xhtml>
    /// as of 2025-09-13.
    CwtClaimName {
        /// GlobalPlatform components ("globalplatform_component: map)
        GlobalPlatformComponents: -261,
        /// Health certificate ("hcert": map).
        Hcert: -260,
        /// Challenge nonce ("EUPHNonce": bstr).
        EuphNonce: -259,
        /// Signing prefix for multi-app restricted operating environment ("EATMAROEPrefix": bstr).
        EatMaroePrefix: -258,
        /// FIDO Device Onboarding EAT ("EAT-FDO": array).
        EatFido: -257,
        /// Reserved value.
        Reserved: 0,
        /// Issuer ("iss": tstr).
        Iss: 1,
        /// Subject ("sub": tstr)
        Sub: 2,
        /// Audience ("aud": tstr)
        Aud: 3,
        /// Expiration Time, as seconds since UNIX epoch ("exp": int/float)
        Exp: 4,
        /// Not Before, as seconds since UNIX epoch ("nbf": int/float)
        Nbf: 5,
        /// Issued at, as seconds since UNIX epoch ("iat": int/float)
        Iat: 6,
        /// CWT ID ("cti": bstr)
        Cti: 7,
        /// Confirmation ("cnf": map)
        Cnf: 8,
        /// Scope of an access token ("scope": bstr/tstr)
        Scope: 9,
        /// Nonce ("eat_nonce": bstr/array)
        Nonce: 10,
        /// The ACE profile a token is supposed to be used with ("ace_profile": int)
        AceProfile: 38,
        /// The client-nonce sent to the AS by the RS via the client ("cnonce": bstr)
        CNonce: 39,
        /// The expiration time of a token measured from when it was received at the RS in seconds ("exi": int)
        Exi: 40,
        /// Universal Entity ID ("ueid": bstr)
        UEID: 256,
        /// Semipermanent UEIDs ("sueids": map)
        SUEIDs: 257,
        /// Hardware OEM ID ("oemid": bstr or int)
        HardwareOemid: 258,
        /// Model identifier for hardware ("hwmodel": bstr)
        HardwareModel: 259,
        /// Hardware Version Identifier ("hwversion": array)
        HardwareVersion: 260,
        /// Uptime ("uptime": uint)
        Uptime: 261,
        /// Indicates whether the software booted was OEM authorized ("oemboot": bool)
        OemAuthorizedBoot: 262,
        /// The status of debug facilities ("dbgstat": uint)
        DebugStatus: 263,
        /// The geographic location ("location": map)
        Location: 264,
        /// The EAT profile followed ("eat_profile": uri or oid)
        EatProfile: 265,
        /// The section containing submodules ("submods": map)
        SubmodulesSection: 266,
        /// The number of times the entity or submodule has been booted ("bootcount": uint)
        BootCount: 267,
        /// Identifies a boot cycle ("bootseed": bstr)
        BootSeed: 268,
        /// Certifications received as Digital Letters of Approval ("dloas": array)
        DLoAs: 269,
        /// The name of the software running in the entity ("swname": tstr)
        SoftwareName: 270,
        /// The version of software running in the entity ("swversion": array)
        SoftwareVersion: 271,
        /// Manifests describing the software installed on the entity ("manifests": array)
        SoftwareManifests: 272,
        /// Measurements of the software, memory configuration, and such on the entity ("measurements": array)
        Measurements: 273,
        /// The results of comparing software measurements to reference values ("measres": array)
        SoftwareMeasurementResults: 274,
        /// The intended use of the EAT ("intuse": uint)
        IntendedUse: 275,
        /// Geohash String ("geohash": text string or array)
        Geohash: 282,
        /// The version of the WM Token ("wmver": unsigned integer)
        WmVersion: 300,
        /// The WM technology vendor ("wmvnd": unsigned integer)
        WmVendor: 301,
        /// The length in bits of the WM pattern ("wmpatlen": unsigned integer)
        WmPatternLen: 302,
        /// The nominal duration of a segment ("wmsegduration": map)
        WmSegmentDuration: 303,
        /// The WM pattern ("wmpattern": COSE_Encrypt0 or COSE_Encrypt or byte string)
        WmPattern: 304,
        /// Used as input to derive the WM pattern for indirect mode ("wmid": text string)
        WmId: 305,
        /// Used as additional input to derive the WM pattern for indirect mode ("wmopid": unsigned integer)
        WmOpId: 306,
        /// The key to use for derivation of the WM pattern in indirect mode ("wmkeyver": unsigned integer)
        WmKeyVer: 307,
        /// Common Access Token Replay ("N/A": unsigned integer)
        CatReplay: 308,
        /// Common Access Token Probability of Rejection ("N/A": array)
        CatPor: 309,
        /// Common Access Token Version ("N/A": unsigned integer)
        CatVersion: 310,
        /// Common Access Token Network IP ("N/A": array)
        CatNetworkIp: 311,
        /// Common Access Token URI ("N/A": map)
        CatUri: 312,
        /// Common Access Token Method ("N/A": array)
        CatMethod: 313,
        /// Common Access Token ALPN ("N/A": array)
        CatAlpn: 314,
        /// Common Access Token Header ("N/A": map)
        CatHeader: 315,
        /// Common Access Token Geographic ISO3166 ("N/A": array)
        CatGeoIso3166: 316,
        /// Common Access Token Geographic Coordinate ("N/A": array)
        CatGeoCoord: 317,
        /// Common Access Token Geographic Altitude ("N/A": array)
        CatGeoAlt: 318,
        /// Common Access Token TLS Public Key ("N/A": byte string)
        CatTlsPublicKey: 319,
        /// Common Access Token If Data ("N/A": string or array)
        CatIfData: 320,
        /// Common Access Token DPoP Settings ("N/A": map)
        CatDPoP: 321,
        /// Common Access Token If ("N/A": map)
        CatIf: 322,
        /// Common Access Token Renewal ("N/A": map)
        CatRenewal: 323,
        /// PSA Client ID ("N/A": signed integer)
        PsaClientId: 2394,
        /// PSA Security Lifecycle ("N/A": unsigned integer)
        PsaSecurityLifecycle: 2395,
        /// PSA Implementation ID ("N/A": byte string)
        PsaImplementationId: 2396,
        /// PSA Certification Reference ("N/A": text string)
        PsaCertificationReference: 2398,
        /// PSA Software Components ("N/A": array)
        PsaSoftwareComponents: 2399,
        /// PSA Verification Service Indicator ("N/A": text string)
        PsaVerificationServiceIndicator: 2400,
    }
}

/// Integer values for CWT claims below this value are reserved for private use.
pub const CWT_CLAIM_PRIVATE_USE_MAX: i64 = -65536;

impl WithPrivateRange for CwtClaimName {
    fn is_private(i: i64) -> bool {
        i < CWT_CLAIM_PRIVATE_USE_MAX
    }
}