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
/// Creates a [`CredentialSchema`] containing the arguments.
///
/// ```
/// # use ockam_entity::credential_type;;
/// let schema = credential_type!["TYPE_ID"; "attribute_of_string_type", (Number, "attribute_of_number_type")];
/// ```
///
/// [`CredentialSchema`]: crate::CredentialSchema
#[macro_export]
macro_rules! credential_type {
    ($t:expr; $($x:expr),* $(,)?) => ({
        use $crate::CredentialAttributeSchema;
        use $crate::CredentialAttributeType::{Number, Utf8String, Blob};

        let mut attributes = vec![CredentialAttributeSchema {
            label: $crate::SECRET_ID.into(),
            description: "".to_string(),
            attribute_type: Blob,
            unknown: true,
        }]; // FIXME: Should we include SECRET_ID in this macro?
        $(attributes.push($x.into());)*

        $crate::CredentialSchema {
            id: $t.into(),
            label: String::new(),
            description: String::new(),
            attributes,
        }
    });
}

/// Creates a [`CredentialAttribute`] vector containing the arguments.
///
/// ```
/// # use ockam_entity::credential_attribute_values;;
/// let values = credential_attribute_values!["ABCD-EFGH", 1];
/// ```
///
/// [`CredentialAttribute`]: crate::CredentialAttribute
#[macro_export]
macro_rules! credential_attribute_values {
    ($($x:expr),* $(,)?) => ({
        use $crate::CredentialAttribute;

        let mut attribute_values: Vec<CredentialAttribute> = vec![];
        $(attribute_values.push($x.into());)*

        attribute_values
    });
}

/// Creates a list of revealed attributes containing the arguments.
///
/// ```
/// # use ockam_entity::reveal_attributes;;
/// let reveal_attributes = reveal_attributes!["ABCD-EFGH", "BDC".to_string()];
/// ```
#[macro_export]
macro_rules! reveal_attributes {
    ($($x:expr),* $(,)?) => ({
        let mut reveal_attributes: Vec<String> = vec![];
        $(reveal_attributes.push($x.into());)*

        reveal_attributes
    });
}