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
pub mod tcti {
    error_chain! {
        errors {
            GenFail {
                description("general failure")
                display("general failure")
            }
            IoError {
                description("I/O failure")
                display("I/O failure")
            }
            NotWrapped(e: u32) {
                description("an unwrapped TCTI error")
                display("an unwrapped TCTI error: 0x{:08X}", e)
            }
        }
    }
}

pub mod tpm {
    error_chain! {
        errors {
            Asymmetric {
                description("asymmetric algorithm not supported or not correct")
                display("asymmetric algorithm not supported or not correct")
            }
            Attributes {
                description("inconsistent attributes")
                display("inconsistent attributes")
            }
            AuthFail {
                description("the authorization HMAC check failed and DA counter incremented")
                display("the authorization HMAC check failed and DA counter incremented")
            }
            BadAuth {
                description("authorization failure without DA implications")
                display("authorization failure without DA implications")
            }
            Disabled {
                description("TPM is disabled")
                display("TPM is disabled")
            }
            Failure {
                description("commands not accepted because of a TPM failure")
                display("commands not accepted because of a TPM failure")
            }
            Exclusive {
                description("command failed because audit sequence required exclusivity")
                display("command failed because audit sequence required exclusivity")
            }
            FormatOne(e: u32) {
                description("an unwrapped TPM format one error")
                display("an unwrapped TPM format one error: 0x{:02X}", e)
            }
            FormatZero(e: u32) {
                description("an unwrapped TPM format zero error")
                display("an unwrapped TPM format zero error: 0x{:02X}", e)
            }
            Handle {
                description("the handle is not correct for the use")
                display("the handle is not correct for the use")
            }
            Hash {
                description("hash algorithm not supported or not appropriate")
                display("hash algorithm not supported or not appropriate")
            }
            Hierarchy {
                description("hierarchy is not enabled or is not correct for the use")
                display("hierarchy is not enabled or is not correct for the use")
            }
            Initialize {
                description("TPM not initialized")
                display("TPM not initialized")
            }
            Insufficient {
                description("the TPM was unable to unmarshal a value\
                    because there were not enough objects in the input")
                display("the TPM was unable to unmarshal a value\
                    because there were not enough objects in the input")
            }
            Kdf {
                description(r#"unsupported key derivation function or
                    function not appropriate for use"#)
                display("unsupported key derivation function or function not appropriate for use")
            }
            Key {
                description("key fields are not compatible with the selected use")
                display("key fields are not compatible with the selected use")
            }
            KeySize {
                description("key size is not supported")
                display("key size is not supported")
            }
            Mgf {
                description("mask generation function not supported")
                display("mask generation function not supported")
            }
            Mode {
                description("mode of operation not supported")
                display("mode of operation not supported")
            }
            Nonce {
                description("invalid nonce size")
                display("invalid nonce size")
            }
            NvAuthorization {
                description("NV access authorization fails in command actions")
                display("NV access authorization fails in command actions")
            }
            NvDefined {
                description("NV Index or persistend object already defined")
                display("NV Index or persistend object already defined")
            }
            NvLocked {
                description("NV access is locked")
                display("NV access is locked")
            }
            NvSpace {
                description("insufficient space for NV allocation")
                display("insufficient space for NV allocation")
            }
            NvUnavailable {
                description("command requires writing of NV and NV is not accessible")
                display("command requires writing of NV and NV is not accessible")
            }
            PhysicalPresence {
                description("auth requires assertion of physical presense")
                display("auth requires assertion of physical presense")
            }
            PolicyFail {
                description("a policy check failed")
                display("a policy check failed")
            }
            Range {
                description("value was out of allowed range")
                display("value was out of allowed range")
            }
            Reboot {
                description("TPM init and startup(clear) is required for TPM to resume operation")
                display("TPM init and startup(clear) is required for TPM to resume operation")
            }
            Scheme {
                description("unsupported or incompatible scheme")
                display("unsupported or incompatible scheme")
            }
            Selector {
                description("union selector is incorrect")
                display("union selector is incorrect")
            }
            Signature {
                description("the signature is not valid")
                display("the signature is not valid")
            }
            Size {
                description("structure is the wrong size")
                display("structure is the wrong size")
            }
            Symmetric {
                description("unsupported symmetric algorithm or key size")
                display("unsupported symmetric algorithm or key size")
            }
            Tag {
                description("incorrect structure tag")
                display("incorrect structure tag")
            }
            Type {
                description("the type of the value is not appropriate for the use")
                display("the type of the value is not appropriate for the use")
            }
            Value {
                description("value is out of range or is not correct for the context")
                display("value is out of range or is not correct for the context")
            }
        }
    }
}

error_chain! {
     foreign_links {
         Io(::std::io::Error);
         Null(::std::ffi::NulError);
     }
    links {
        Tpm(tpm::Error, tpm::ErrorKind);
        Tcti(tcti::Error, tcti::ErrorKind);
    }
    errors {
        AppError(e: u32) {
            description("unknown app level error")
            display("unknown app level error: 0x{:08X}", e)
        }
        BadSize(e: String) {
            description("invalid size provided")
            display("invalid size provided: {}", e)
        }
        FeatureError(e: u32) {
            description("unknown feature error")
            display("unknown app level error: 0x{:08X}", e)
        }
        EsapiError(e: u32) {
            description("unknown ESAPI error")
            display("unknown ESAPI error: 0x{:08X}", e)
        }
        ResMgrTpmError(e: u32) {
            description("unknown resource manager TPM error")
            display("unknown resource manager TPM error: 0x{:08X}", e)
        }
        ResMgrError(e: u32) {
            description("unknown resource manager error")
            display("unknown resource manager error: 0x{:08X}", e)
        }
        DriverError(e: u32) {
            description("unknown driver error")
            display("unknown driver error: 0x{:08X}", e)
        }
        Unknown(e: u32) {
            description("unknown error")
            display("unknown error: 0x{:08X}", e)
        }
    }
}