azure_security_keyvault_keys 0.14.0

Rust wrappers around Microsoft Azure REST APIs - Azure Key Vault Keys
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// Code generated by Microsoft (R) Rust Code Generator. DO NOT EDIT.

use super::{
    CurveName, DeletionRecoveryLevel, EncryptionAlgorithm, KeyEncryptionAlgorithm, KeyOperation,
    KeyRotationPolicyAction, KeyType, SignatureAlgorithm,
};
use azure_core::{base64, fmt::SafeDebug, time::OffsetDateTime};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// The backup key result, containing the backup blob.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct BackupKeyResult {
    /// The backup blob containing the backed up key.
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing
    )]
    pub value: Option<Vec<u8>>,
}

/// The key create parameters.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct CreateKeyParameters {
    /// Elliptic curve name. For valid values, see JsonWebKeyCurveName.
    #[serde(rename = "crv", skip_serializing_if = "Option::is_none")]
    pub curve: Option<CurveName>,

    /// The attributes of a key managed by the key vault service.
    #[serde(rename = "attributes", skip_serializing_if = "Option::is_none")]
    pub key_attributes: Option<KeyAttributes>,

    /// Json web key operations. For more information on possible key operations, see JsonWebKeyOperation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub key_ops: Option<Vec<KeyOperation>>,

    /// The key size in bits. For example: 2048, 3072, or 4096 for RSA.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub key_size: Option<i32>,

    /// The type of key to create. For valid values, see JsonWebKeyType.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub kty: Option<KeyType>,

    /// The public exponent for a RSA key.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub public_exponent: Option<i32>,

    /// The policy rules under which the key can be exported.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub release_policy: Option<KeyReleasePolicy>,

    /// Application specific metadata in the form of key-value pairs.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<HashMap<String, String>>,
}

/// A DeletedKeyBundle consisting of a WebKey plus its Attributes and deletion info
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct DeletedKey {
    /// The key management attributes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub attributes: Option<KeyAttributes>,

    /// The time when the key was deleted, in UTC
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        rename = "deletedDate",
        skip_serializing,
        with = "azure_core::time::unix_time::option"
    )]
    pub deleted_date: Option<OffsetDateTime>,

    /// The Json web key.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub key: Option<JsonWebKey>,

    /// True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will be true.
    ///
    /// Operational visibility: Read
    #[serde(skip_serializing)]
    pub managed: Option<bool>,

    /// The url of the recovery object, used to identify and recover the deleted key.
    #[serde(rename = "recoveryId", skip_serializing_if = "Option::is_none")]
    pub recovery_id: Option<String>,

    /// The policy rules under which the key can be exported.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub release_policy: Option<KeyReleasePolicy>,

    /// The time when the key is scheduled to be purged, in UTC
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        rename = "scheduledPurgeDate",
        skip_serializing,
        with = "azure_core::time::unix_time::option"
    )]
    pub scheduled_purge_date: Option<OffsetDateTime>,

    /// Application specific metadata in the form of key-value pairs.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<HashMap<String, String>>,
}

/// The deleted key item containing the deleted key metadata and information about deletion.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct DeletedKeyProperties {
    /// The key management attributes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub attributes: Option<KeyAttributes>,

    /// The time when the key was deleted, in UTC
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        rename = "deletedDate",
        skip_serializing,
        with = "azure_core::time::unix_time::option"
    )]
    pub deleted_date: Option<OffsetDateTime>,

    /// Key identifier.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub kid: Option<String>,

    /// True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will be true.
    ///
    /// Operational visibility: Read
    #[serde(skip_serializing)]
    pub managed: Option<bool>,

    /// The url of the recovery object, used to identify and recover the deleted key.
    #[serde(rename = "recoveryId", skip_serializing_if = "Option::is_none")]
    pub recovery_id: Option<String>,

    /// The time when the key is scheduled to be purged, in UTC
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        rename = "scheduledPurgeDate",
        skip_serializing,
        with = "azure_core::time::unix_time::option"
    )]
    pub scheduled_purge_date: Option<OffsetDateTime>,

    /// Application specific metadata in the form of key-value pairs.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<HashMap<String, String>>,
}

/// The get random bytes request object.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct GetRandomBytesParameters {
    /// The requested number of random bytes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub count: Option<i32>,
}

/// The key import parameters.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct ImportKeyParameters {
    /// Whether to import as a hardware key (HSM) or software key.
    #[serde(rename = "Hsm", skip_serializing_if = "Option::is_none")]
    pub hsm: Option<bool>,

    /// The Json web key
    #[serde(skip_serializing_if = "Option::is_none")]
    pub key: Option<JsonWebKey>,

    /// The key management attributes.
    #[serde(rename = "attributes", skip_serializing_if = "Option::is_none")]
    pub key_attributes: Option<KeyAttributes>,

    /// The policy rules under which the key can be exported.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub release_policy: Option<KeyReleasePolicy>,

    /// Application specific metadata in the form of key-value pairs.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<HashMap<String, String>>,
}

/// As of <http://tools.ietf.org/html/draft-ietf-jose-json-web-key-18>
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct JsonWebKey {
    /// Elliptic curve name. For valid values, see JsonWebKeyCurveName.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub crv: Option<CurveName>,

    /// RSA private exponent, or the D component of an EC private key.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub d: Option<Vec<u8>>,

    /// RSA private key parameter.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub dp: Option<Vec<u8>>,

    /// RSA private key parameter.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub dq: Option<Vec<u8>>,

    /// RSA public exponent.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub e: Option<Vec<u8>>,

    /// Symmetric key.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub k: Option<Vec<u8>>,

    /// Json web key operations. For more information on possible key operations, see JsonWebKeyOperation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub key_ops: Option<Vec<String>>,

    /// Key identifier.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub kid: Option<String>,

    /// JsonWebKey Key Type (kty), as defined in <https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-40>.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub kty: Option<KeyType>,

    /// RSA modulus.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub n: Option<Vec<u8>>,

    /// RSA secret prime.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub p: Option<Vec<u8>>,

    /// RSA secret prime, with p < q.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub q: Option<Vec<u8>>,

    /// RSA private key parameter.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub qi: Option<Vec<u8>>,

    /// Protected Key, used with 'Bring Your Own Key'.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        rename = "key_hsm",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub t: Option<Vec<u8>>,

    /// X component of an EC public key.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub x: Option<Vec<u8>>,

    /// Y component of an EC public key.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub y: Option<Vec<u8>>,
}

/// A KeyBundle consisting of a WebKey plus its attributes.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct Key {
    /// The key management attributes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub attributes: Option<KeyAttributes>,

    /// The Json web key.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub key: Option<JsonWebKey>,

    /// True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will be true.
    ///
    /// Operational visibility: Read
    #[serde(skip_serializing)]
    pub managed: Option<bool>,

    /// The policy rules under which the key can be exported.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub release_policy: Option<KeyReleasePolicy>,

    /// Application specific metadata in the form of key-value pairs.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<HashMap<String, String>>,
}

/// The key attestation information.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct KeyAttestation {
    /// A base64url-encoded string containing certificates in PEM format, used for attestation validation.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        rename = "certificatePemFile",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub certificate_pem_file: Option<Vec<u8>>,

    /// The attestation blob bytes encoded as base64url string corresponding to a private key.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        rename = "privateKeyAttestation",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub private_key_attestation: Option<Vec<u8>>,

    /// The attestation blob bytes encoded as base64url string corresponding to a public key in case of asymmetric key.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        rename = "publicKeyAttestation",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub public_key_attestation: Option<Vec<u8>>,

    /// The version of the attestation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub version: Option<String>,
}

/// The attributes of a key managed by the key vault service.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct KeyAttributes {
    /// The key or key version attestation information.
    ///
    /// Operational visibility: Read
    #[serde(skip_serializing)]
    pub attestation: Option<KeyAttestation>,

    /// Creation time in UTC.
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        skip_serializing,
        with = "azure_core::time::unix_time::option"
    )]
    pub created: Option<OffsetDateTime>,

    /// Determines whether the object is enabled.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enabled: Option<bool>,

    /// Expiry date in UTC.
    #[serde(
        default,
        rename = "exp",
        skip_serializing_if = "Option::is_none",
        with = "azure_core::time::unix_time::option"
    )]
    pub expires: Option<OffsetDateTime>,

    /// Indicates if the private key can be exported. Release policy must be provided when creating the first version of an exportable
    /// key.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub exportable: Option<bool>,

    /// The underlying HSM Platform.
    ///
    /// Operational visibility: Read
    #[serde(rename = "hsmPlatform", skip_serializing)]
    pub hsm_platform: Option<String>,

    /// Not before date in UTC.
    #[serde(
        default,
        rename = "nbf",
        skip_serializing_if = "Option::is_none",
        with = "azure_core::time::unix_time::option"
    )]
    pub not_before: Option<OffsetDateTime>,

    /// softDelete data retention days. Value should be >=7 and <=90 when softDelete enabled, otherwise 0.
    ///
    /// Operational visibility: Read
    #[serde(rename = "recoverableDays", skip_serializing)]
    pub recoverable_days: Option<i32>,

    /// Reflects the deletion recovery level currently in effect for keys in the current vault. If it contains 'Purgeable' the
    /// key can be permanently deleted by a privileged user; otherwise, only the system can purge the key, at the end of the retention
    /// interval.
    ///
    /// Operational visibility: Read
    #[serde(rename = "recoveryLevel", skip_serializing)]
    pub recovery_level: Option<DeletionRecoveryLevel>,

    /// Last updated time in UTC.
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        skip_serializing,
        with = "azure_core::time::unix_time::option"
    )]
    pub updated: Option<OffsetDateTime>,
}

/// The key operations parameters.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct KeyOperationParameters {
    /// Additional data to authenticate but not encrypt/decrypt when using authenticated crypto algorithms.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        rename = "aad",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub additional_authenticated_data: Option<Vec<u8>>,

    /// algorithm identifier
    #[serde(rename = "alg", skip_serializing_if = "Option::is_none")]
    pub algorithm: Option<EncryptionAlgorithm>,

    /// The tag to authenticate when performing decryption with an authenticated algorithm.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        rename = "tag",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub authentication_tag: Option<Vec<u8>>,

    /// Cryptographically random, non-repeating initialization vector for symmetric algorithms.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub iv: Option<Vec<u8>>,

    /// The value to operate on.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub value: Option<Vec<u8>>,
}

/// The key operation result.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct KeyOperationResult {
    /// Additional data to authenticate but not encrypt/decrypt when using authenticated crypto algorithms.
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        rename = "aad",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing
    )]
    pub additional_authenticated_data: Option<Vec<u8>>,

    /// The tag to authenticate when performing decryption with an authenticated algorithm.
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        rename = "tag",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing
    )]
    pub authentication_tag: Option<Vec<u8>>,

    /// Cryptographically random, non-repeating initialization vector for symmetric algorithms.
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing
    )]
    pub iv: Option<Vec<u8>>,

    /// Key identifier
    ///
    /// You should record this when returned from [`KeyClient::encrypt()`](crate::KeyClient::encrypt), [`sign()`](crate::KeyClient::sign),
    /// and [`wrap_key()`](crate::KeyClient::wrap_key) so you can later parse it with [`ResourceId`](crate::ResourceId)
    /// and pass the version to [`decrypt()`](crate::KeyClient::decrypt), [`verify()`](crate::KeyClient::verify),
    /// and [`unwrap_key()`](crate::KeyClient::unwrap_key).
    /// You can pass an empty string for the version to those functions to select the latest key version
    /// but if you don't record the specific version used encrypting, signing, or wrapping a key, key rotation can make the data
    /// inaccessible.
    ///
    /// Operational visibility: Read
    #[serde(skip_serializing)]
    pub kid: Option<String>,

    /// The result of the operation.
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        rename = "value",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing
    )]
    pub result: Option<Vec<u8>>,
}

/// The key item containing key metadata.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct KeyProperties {
    /// The key management attributes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub attributes: Option<KeyAttributes>,

    /// Key identifier.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub kid: Option<String>,

    /// True if the key's lifetime is managed by key vault. If this is a key backing a certificate, then managed will be true.
    ///
    /// Operational visibility: Read
    #[serde(skip_serializing)]
    pub managed: Option<bool>,

    /// Application specific metadata in the form of key-value pairs.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<HashMap<String, String>>,
}

/// The policy rules under which the key can be exported.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct KeyReleasePolicy {
    /// Content type and version of key release policy
    #[serde(rename = "contentType", skip_serializing_if = "Option::is_none")]
    pub content_type: Option<String>,

    /// Blob encoding the policy rules under which the key can be released. Blob must be base64 URL encoded.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        rename = "data",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub encoded_policy: Option<Vec<u8>>,

    /// Defines the mutability state of the policy. Once marked immutable, this flag cannot be reset and the policy cannot be
    /// changed under any circumstances.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub immutable: Option<bool>,
}

/// The release result, containing the released key.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct KeyReleaseResult {
    /// A signed object containing the released key.
    ///
    /// Operational visibility: Read
    #[serde(skip_serializing)]
    pub value: Option<String>,
}

/// Management policy for a key.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct KeyRotationPolicy {
    /// The key rotation policy attributes.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub attributes: Option<KeyRotationPolicyAttributes>,

    /// The key policy id.
    ///
    /// Operational visibility: Read
    #[serde(skip_serializing)]
    pub id: Option<String>,

    /// Actions that will be performed by Key Vault over the lifetime of a key. For preview, lifetimeActions can only have two
    /// items at maximum: one for rotate, one for notify. Notification time would be default to 30 days before expiry and it is
    /// not configurable.
    #[serde(rename = "lifetimeActions", skip_serializing_if = "Option::is_none")]
    pub lifetime_actions: Option<Vec<LifetimeAction>>,
}

/// The key rotation policy attributes.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct KeyRotationPolicyAttributes {
    /// The key rotation policy created time in UTC.
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        skip_serializing,
        with = "azure_core::time::unix_time::option"
    )]
    pub created: Option<OffsetDateTime>,

    /// The expiryTime will be applied on the new key version. It should be at least 28 days. It will be in ISO 8601 Format. Examples:
    /// 90 days: P90D, 3 months: P3M, 48 hours: PT48H, 1 year and 10 days: P1Y10D
    #[serde(rename = "expiryTime", skip_serializing_if = "Option::is_none")]
    pub expiry_time: Option<String>,

    /// The key rotation policy's last updated time in UTC.
    ///
    /// Operational visibility: Read
    #[serde(
        default,
        skip_serializing,
        with = "azure_core::time::unix_time::option"
    )]
    pub updated: Option<OffsetDateTime>,
}

/// The key vault error exception.
#[derive(Clone, Deserialize, SafeDebug, Serialize)]
pub struct KeyVaultError {
    /// The key vault server error.
    ///
    /// Operational visibility: Read
    #[serde(skip_serializing)]
    pub error: Option<KeyVaultErrorError>,
}

/// The key vault server error.
#[derive(Clone, Deserialize, SafeDebug, Serialize)]
pub struct KeyVaultErrorError {
    /// The error code.
    ///
    /// Operational visibility: Read
    #[serde(skip_serializing)]
    pub code: Option<String>,

    /// The key vault server error.
    ///
    /// Operational visibility: Read
    #[serde(rename = "innererror", skip_serializing)]
    pub inner_error: Option<Box<KeyVaultErrorError>>,

    /// The error message.
    ///
    /// Operational visibility: Read
    #[serde(skip_serializing)]
    pub message: Option<String>,
}

/// The key verify result.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct KeyVerifyResult {
    /// True if the signature is verified, otherwise false.
    ///
    /// Operational visibility: Read
    #[serde(skip_serializing)]
    pub value: Option<bool>,
}

/// Action and its trigger that will be performed by Key Vault over the lifetime of a key.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct LifetimeAction {
    /// The action that will be executed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub action: Option<LifetimeActionType>,

    /// The condition that will execute the action.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub trigger: Option<LifetimeActionTrigger>,
}

/// A condition to be satisfied for an action to be executed.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct LifetimeActionTrigger {
    /// Time after creation to attempt to rotate. It only applies to rotate. It will be in ISO 8601 duration format. Example:
    /// 90 days : "P90D"
    #[serde(rename = "timeAfterCreate", skip_serializing_if = "Option::is_none")]
    pub time_after_create: Option<String>,

    /// Time before expiry to attempt to rotate or notify. It will be in ISO 8601 duration format. Example: 90 days : "P90D"
    #[serde(rename = "timeBeforeExpiry", skip_serializing_if = "Option::is_none")]
    pub time_before_expiry: Option<String>,
}

/// The action that will be executed.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct LifetimeActionType {
    /// The type of the action. The value should be compared case-insensitively.
    #[serde(rename = "type", skip_serializing_if = "Option::is_none")]
    pub type_prop: Option<KeyRotationPolicyAction>,
}

/// A list of keys that have been deleted in this vault.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct ListDeletedKeyPropertiesResult {
    /// The URL to get the next set of deleted keys.
    ///
    /// Operational visibility: Read
    #[serde(rename = "nextLink", skip_serializing)]
    pub next_link: Option<String>,

    /// A response message containing a list of deleted keys in the key vault along with a link to the next page of deleted keys.
    ///
    /// Operational visibility: Read
    #[serde(default, skip_serializing)]
    pub value: Vec<DeletedKeyProperties>,
}

/// The key list result.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct ListKeyPropertiesResult {
    /// The URL to get the next set of keys.
    ///
    /// Operational visibility: Read
    #[serde(rename = "nextLink", skip_serializing)]
    pub next_link: Option<String>,

    /// A response message containing a list of keys in the key vault along with a link to the next page of keys.
    ///
    /// Operational visibility: Read
    #[serde(default, skip_serializing)]
    pub value: Vec<KeyProperties>,
}

/// The get random bytes response object containing the bytes.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
#[non_exhaustive]
pub struct RandomBytes {
    /// The bytes encoded as a base64url string.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub value: Option<Vec<u8>>,
}

/// The release key parameters.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct ReleaseParameters {
    /// The encryption algorithm to use to protected the exported key material
    #[serde(rename = "enc", skip_serializing_if = "Option::is_none")]
    pub algorithm: Option<KeyEncryptionAlgorithm>,

    /// A client provided nonce for freshness.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub nonce: Option<String>,

    /// The attestation assertion for the target of the key release.
    #[serde(rename = "target", skip_serializing_if = "Option::is_none")]
    pub target_attestation_token: Option<String>,
}

/// The key restore parameters.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct RestoreKeyParameters {
    /// The backup blob associated with a key bundle.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        rename = "value",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub key_backup: Option<Vec<u8>>,
}

/// The key operations parameters.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct SignParameters {
    /// The signing/verification algorithm identifier. For more information on possible algorithm types, see JsonWebKeySignatureAlgorithm.
    #[serde(rename = "alg", skip_serializing_if = "Option::is_none")]
    pub algorithm: Option<SignatureAlgorithm>,

    /// The value to operate on.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub value: Option<Vec<u8>>,
}

/// The key update parameters.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct UpdateKeyPropertiesParameters {
    /// The attributes of a key managed by the key vault service.
    #[serde(rename = "attributes", skip_serializing_if = "Option::is_none")]
    pub key_attributes: Option<KeyAttributes>,

    /// Json web key operations. For more information on possible key operations, see JsonWebKeyOperation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub key_ops: Option<Vec<KeyOperation>>,

    /// The policy rules under which the key can be exported.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub release_policy: Option<KeyReleasePolicy>,

    /// Application specific metadata in the form of key-value pairs.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub tags: Option<HashMap<String, String>>,
}

/// The key verify parameters.
#[derive(Clone, Default, Deserialize, SafeDebug, Serialize)]
pub struct VerifyParameters {
    /// The signing/verification algorithm. For more information on possible algorithm types, see JsonWebKeySignatureAlgorithm.
    #[serde(rename = "alg", skip_serializing_if = "Option::is_none")]
    pub algorithm: Option<SignatureAlgorithm>,

    /// The digest used for signing.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub digest: Option<Vec<u8>>,

    /// The signature to be verified.
    #[serde(
        default,
        deserialize_with = "base64::option::deserialize_url_safe",
        rename = "value",
        serialize_with = "base64::option::serialize_url_safe",
        skip_serializing_if = "Option::is_none"
    )]
    pub signature: Option<Vec<u8>>,
}