splinter 0.6.14

Splinter is a privacy-focused platform for distributed applications that provides a blockchain-inspired networking environment for communication and transactions between organizations.
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
// Copyright 2018-2022 Cargill Incorporated
//
// 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.

//! Protocol structs for splinter connection authorization.
//!
//! These structs are used to operate on the messages that are sent and received during the
//! authorization process for connections.

use crate::protos::authorization;
use crate::protos::prelude::*;
use crate::public_key::PublicKey;

/// The authorization message envelope.
#[derive(Debug)]
pub enum AuthorizationMessage {
    ConnectRequest(ConnectRequest),
    ConnectResponse(ConnectResponse),
    Authorized(Authorized),
    AuthorizationError(AuthorizationError),

    TrustRequest(TrustRequest),

    // v1 messages
    AuthComplete(AuthComplete),
    AuthProtocolRequest(AuthProtocolRequest),
    AuthProtocolResponse(AuthProtocolResponse),

    AuthTrustRequest(AuthTrustRequest),
    AuthTrustResponse(AuthTrustResponse),

    AuthChallengeNonceRequest(AuthChallengeNonceRequest),
    AuthChallengeNonceResponse(AuthChallengeNonceResponse),
    AuthChallengeSubmitRequest(AuthChallengeSubmitRequest),
    AuthChallengeSubmitResponse(AuthChallengeSubmitResponse),
}

/// The possible types of authorization that may be computed during the handshake.
#[derive(Debug)]
pub enum AuthorizationType {
    Trust,
}

/// A connection request message.
///
/// This message provides information from the incoming connection.
#[derive(Debug)]
pub enum ConnectRequest {
    Bidirectional,
    Unidirectional,
}

/// A connection response message.
///
/// This message provides information for the incoming peer regarding the types of authorization
/// accepted.
#[derive(Debug)]
pub struct ConnectResponse {
    pub accepted_authorization_types: Vec<AuthorizationType>,
}

/// A trust request.
///
/// A trust request is sent in response to a Connect Message, if the node is using trust
/// authentication as its means of allowing a node to connect.
#[derive(Debug)]
pub struct TrustRequest {
    pub identity: String,
}

/// A successful authorization message.
///
/// This message is returned after either a TrustResponse has been returned by the remote
/// connection.
#[derive(Debug)]
pub struct Authorized;

/// A message indicating an error in authorization.
///
/// This includes failed authorizations, or invalid messages during the authorization handshake
/// conversation.
#[derive(Debug)]
pub enum AuthorizationError {
    AuthorizationRejected(String),
}

impl FromProto<authorization::ConnectRequest> for ConnectRequest {
    fn from_proto(source: authorization::ConnectRequest) -> Result<Self, ProtoConversionError> {
        use authorization::ConnectRequest_HandshakeMode::*;
        match source.handshake_mode {
            BIDIRECTIONAL => Ok(ConnectRequest::Bidirectional),
            UNIDIRECTIONAL => Ok(ConnectRequest::Unidirectional),
            UNSET_HANDSHAKE_MODE => Err(ProtoConversionError::InvalidTypeError(
                "No handshake mode was set".into(),
            )),
        }
    }
}

impl FromNative<ConnectRequest> for authorization::ConnectRequest {
    fn from_native(req: ConnectRequest) -> Result<Self, ProtoConversionError> {
        let mut proto_request = authorization::ConnectRequest::new();
        use authorization::ConnectRequest_HandshakeMode::*;
        proto_request.set_handshake_mode(match req {
            ConnectRequest::Bidirectional => BIDIRECTIONAL,
            ConnectRequest::Unidirectional => UNIDIRECTIONAL,
        });
        Ok(proto_request)
    }
}

impl FromProto<authorization::ConnectResponse> for ConnectResponse {
    fn from_proto(source: authorization::ConnectResponse) -> Result<Self, ProtoConversionError> {
        use authorization::ConnectResponse_AuthorizationType::*;
        Ok(Self {
            accepted_authorization_types: source
                .get_accepted_authorization_types()
                .iter()
                .map(|t| match t {
                    TRUST => Ok(AuthorizationType::Trust),
                    UNSET_AUTHORIZATION_TYPE => Err(ProtoConversionError::InvalidTypeError(
                        "no authorization type was set".into(),
                    )),
                })
                .collect::<Result<Vec<AuthorizationType>, ProtoConversionError>>()?,
        })
    }
}

impl FromNative<ConnectResponse> for authorization::ConnectResponse {
    fn from_native(source: ConnectResponse) -> Result<Self, ProtoConversionError> {
        let mut response = authorization::ConnectResponse::new();

        response.set_accepted_authorization_types(
            source
                .accepted_authorization_types
                .into_iter()
                .map(|auth_type| match auth_type {
                    AuthorizationType::Trust => {
                        authorization::ConnectResponse_AuthorizationType::TRUST
                    }
                })
                .collect(),
        );

        Ok(response)
    }
}

impl FromProto<authorization::TrustRequest> for TrustRequest {
    fn from_proto(mut source: authorization::TrustRequest) -> Result<Self, ProtoConversionError> {
        Ok(Self {
            identity: source.take_identity(),
        })
    }
}

impl FromNative<TrustRequest> for authorization::TrustRequest {
    fn from_native(source: TrustRequest) -> Result<Self, ProtoConversionError> {
        let mut request = authorization::TrustRequest::new();
        request.set_identity(source.identity);

        Ok(request)
    }
}

impl FromProto<authorization::AuthorizedMessage> for Authorized {
    fn from_proto(_: authorization::AuthorizedMessage) -> Result<Self, ProtoConversionError> {
        Ok(Authorized)
    }
}

impl FromNative<Authorized> for authorization::AuthorizedMessage {
    fn from_native(_: Authorized) -> Result<Self, ProtoConversionError> {
        Ok(authorization::AuthorizedMessage::new())
    }
}

impl FromProto<authorization::AuthorizationError> for AuthorizationError {
    fn from_proto(
        mut source: authorization::AuthorizationError,
    ) -> Result<Self, ProtoConversionError> {
        use authorization::AuthorizationError_AuthorizationErrorType::*;
        match source.error_type {
            AUTHORIZATION_REJECTED => Ok(AuthorizationError::AuthorizationRejected(
                source.take_error_message(),
            )),
            UNSET_AUTHORIZATION_ERROR_TYPE => Err(ProtoConversionError::InvalidTypeError(
                "No error type set".into(),
            )),
        }
    }
}

impl FromNative<AuthorizationError> for authorization::AuthorizationError {
    fn from_native(source: AuthorizationError) -> Result<Self, ProtoConversionError> {
        use authorization::AuthorizationError_AuthorizationErrorType::*;
        let mut error = authorization::AuthorizationError::new();
        match source {
            AuthorizationError::AuthorizationRejected(message) => {
                error.set_error_type(AUTHORIZATION_REJECTED);
                error.set_error_message(message);
            }
        }
        Ok(error)
    }
}

// ------------- v1 messages ----------

/// A successful authorization message.
///
/// This message is returned after Trust or Challenge authorization is completed
#[derive(Debug)]
pub struct AuthComplete;

/// A protocol request message.
///
/// This message provides supported protocol versions and requests that an agreed upon version is
/// returned.
#[derive(Debug)]
pub struct AuthProtocolRequest {
    pub auth_protocol_min: u32,
    pub auth_protocol_max: u32,
}

#[derive(Debug, Clone)]
pub enum PeerAuthorizationType {
    Trust,
    Challenge,
}

/// A protocol response message.
///
/// This message returns the agreed upon authorization protocol and a list of supported peer
/// authorization types.
#[derive(Debug)]
pub struct AuthProtocolResponse {
    pub auth_protocol: u32,
    pub accepted_authorization_type: Vec<PeerAuthorizationType>,
}

/// A trust request.
///
/// A trust request is sent to a node, if the other node accepts trust authorization a trust
/// response will be returned.
#[derive(Debug)]
pub struct AuthTrustRequest {
    pub identity: String,
}

/// A successful trust authorization.
///
/// This message is returned if trust a request is accepted
#[derive(Debug)]
pub struct AuthTrustResponse;

/// A challenge nounce request
///
/// This request is for a nonce that will be used to create the signature used in the
/// AuthChallengeSubmitRequest message
#[derive(Debug)]
pub struct AuthChallengeNonceRequest;

/// A challenge nounce response
///
/// This response contains nonce that must be used to create the signature used in the
/// AuthChallengeSubmitRequest message
#[derive(Debug)]
pub struct AuthChallengeNonceResponse {
    pub nonce: Vec<u8>,
}

#[derive(Debug)]
pub struct SubmitRequest {
    pub public_key: PublicKey,
    pub signature: Vec<u8>,
}

/// A challenge submit request
///
/// This request contains the signature created from the nonce in the AuthChallengeNonceResponse
/// and the public key for the signature.
#[derive(Debug)]
pub struct AuthChallengeSubmitRequest {
    pub submit_requests: Vec<SubmitRequest>,
}

/// A successful challenge authorization.
///
/// This message is returned if challenge submit request is accepted
#[derive(Debug)]
pub struct AuthChallengeSubmitResponse {
    pub public_key: PublicKey,
}

impl FromProto<authorization::AuthComplete> for AuthComplete {
    fn from_proto(_: authorization::AuthComplete) -> Result<Self, ProtoConversionError> {
        Ok(AuthComplete)
    }
}

impl FromNative<AuthComplete> for authorization::AuthComplete {
    fn from_native(_: AuthComplete) -> Result<Self, ProtoConversionError> {
        Ok(authorization::AuthComplete::new())
    }
}

impl FromProto<authorization::AuthProtocolRequest> for AuthProtocolRequest {
    fn from_proto(
        source: authorization::AuthProtocolRequest,
    ) -> Result<Self, ProtoConversionError> {
        Ok(AuthProtocolRequest {
            auth_protocol_min: source.get_auth_protocol_min(),
            auth_protocol_max: source.get_auth_protocol_max(),
        })
    }
}

impl FromNative<AuthProtocolRequest> for authorization::AuthProtocolRequest {
    fn from_native(req: AuthProtocolRequest) -> Result<Self, ProtoConversionError> {
        let mut proto_request = authorization::AuthProtocolRequest::new();
        proto_request.set_auth_protocol_min(req.auth_protocol_min);
        proto_request.set_auth_protocol_max(req.auth_protocol_max);
        Ok(proto_request)
    }
}

impl FromProto<authorization::AuthProtocolResponse> for AuthProtocolResponse {
    fn from_proto(
        source: authorization::AuthProtocolResponse,
    ) -> Result<Self, ProtoConversionError> {
        use authorization::AuthProtocolResponse_PeerAuthorizationType::*;
        Ok(AuthProtocolResponse {
            auth_protocol: source.get_auth_protocol(),
            accepted_authorization_type: source
                .get_accepted_authorization_type()
                .iter()
                .map(|auth_type| match auth_type {
                    UNSET_AUTHORIZATION_TYPE => Err(ProtoConversionError::InvalidTypeError(
                        "No handshake mode was set".into(),
                    )),
                    TRUST => Ok(PeerAuthorizationType::Trust),
                    CHALLENGE => Ok(PeerAuthorizationType::Challenge),
                })
                .collect::<Result<Vec<_>, ProtoConversionError>>()?,
        })
    }
}

impl FromNative<AuthProtocolResponse> for authorization::AuthProtocolResponse {
    fn from_native(req: AuthProtocolResponse) -> Result<Self, ProtoConversionError> {
        use authorization::AuthProtocolResponse_PeerAuthorizationType::*;

        let mut proto_request = authorization::AuthProtocolResponse::new();
        proto_request.set_auth_protocol(req.auth_protocol);
        proto_request.set_accepted_authorization_type(
            req.accepted_authorization_type
                .iter()
                .map(|auth_type| match auth_type {
                    PeerAuthorizationType::Trust => TRUST,
                    PeerAuthorizationType::Challenge => CHALLENGE,
                })
                .collect(),
        );
        Ok(proto_request)
    }
}

impl FromProto<authorization::AuthTrustRequest> for AuthTrustRequest {
    fn from_proto(
        mut source: authorization::AuthTrustRequest,
    ) -> Result<Self, ProtoConversionError> {
        Ok(AuthTrustRequest {
            identity: source.take_identity(),
        })
    }
}

impl FromNative<AuthTrustRequest> for authorization::AuthTrustRequest {
    fn from_native(req: AuthTrustRequest) -> Result<Self, ProtoConversionError> {
        let mut proto_request = authorization::AuthTrustRequest::new();
        proto_request.set_identity(req.identity);
        Ok(proto_request)
    }
}

impl FromProto<authorization::AuthTrustResponse> for AuthTrustResponse {
    fn from_proto(_: authorization::AuthTrustResponse) -> Result<Self, ProtoConversionError> {
        Ok(AuthTrustResponse)
    }
}

impl FromNative<AuthTrustResponse> for authorization::AuthTrustResponse {
    fn from_native(_: AuthTrustResponse) -> Result<Self, ProtoConversionError> {
        Ok(authorization::AuthTrustResponse::new())
    }
}

impl FromProto<authorization::AuthChallengeNonceRequest> for AuthChallengeNonceRequest {
    fn from_proto(
        _: authorization::AuthChallengeNonceRequest,
    ) -> Result<Self, ProtoConversionError> {
        Ok(AuthChallengeNonceRequest)
    }
}

impl FromNative<AuthChallengeNonceRequest> for authorization::AuthChallengeNonceRequest {
    fn from_native(_: AuthChallengeNonceRequest) -> Result<Self, ProtoConversionError> {
        Ok(authorization::AuthChallengeNonceRequest::new())
    }
}

impl FromProto<authorization::AuthChallengeNonceResponse> for AuthChallengeNonceResponse {
    fn from_proto(
        mut source: authorization::AuthChallengeNonceResponse,
    ) -> Result<Self, ProtoConversionError> {
        Ok(AuthChallengeNonceResponse {
            nonce: source.take_nonce(),
        })
    }
}

impl FromNative<AuthChallengeNonceResponse> for authorization::AuthChallengeNonceResponse {
    fn from_native(req: AuthChallengeNonceResponse) -> Result<Self, ProtoConversionError> {
        let mut proto_request = authorization::AuthChallengeNonceResponse::new();
        proto_request.set_nonce(req.nonce);
        Ok(proto_request)
    }
}

impl FromProto<authorization::AuthChallengeSubmitRequest> for AuthChallengeSubmitRequest {
    fn from_proto(
        mut source: authorization::AuthChallengeSubmitRequest,
    ) -> Result<Self, ProtoConversionError> {
        Ok(AuthChallengeSubmitRequest {
            submit_requests: source
                .take_submit_requests()
                .into_iter()
                .map(|mut submit_request| SubmitRequest {
                    public_key: PublicKey::from_bytes(submit_request.take_public_key()),
                    signature: submit_request.take_signature(),
                })
                .collect(),
        })
    }
}

impl FromNative<AuthChallengeSubmitRequest> for authorization::AuthChallengeSubmitRequest {
    fn from_native(req: AuthChallengeSubmitRequest) -> Result<Self, ProtoConversionError> {
        let mut proto_request = authorization::AuthChallengeSubmitRequest::new();
        let submit_requests = req
            .submit_requests
            .iter()
            .map(|submit_request| {
                let mut proto_submit_request = authorization::SubmitRequest::new();
                proto_submit_request.set_public_key(submit_request.public_key.clone().into_bytes());
                proto_submit_request.set_signature(submit_request.signature.to_vec());
                proto_submit_request
            })
            .collect();

        proto_request.set_submit_requests(submit_requests);
        Ok(proto_request)
    }
}

impl FromNative<AuthChallengeSubmitResponse> for authorization::AuthChallengeSubmitResponse {
    fn from_native(response: AuthChallengeSubmitResponse) -> Result<Self, ProtoConversionError> {
        let mut proto_response = authorization::AuthChallengeSubmitResponse::new();
        proto_response.set_public_key(response.public_key.into_bytes());
        Ok(proto_response)
    }
}

impl FromProto<authorization::AuthChallengeSubmitResponse> for AuthChallengeSubmitResponse {
    fn from_proto(
        mut source: authorization::AuthChallengeSubmitResponse,
    ) -> Result<Self, ProtoConversionError> {
        Ok(AuthChallengeSubmitResponse {
            public_key: PublicKey::from_bytes(source.take_public_key()),
        })
    }
}

impl FromProto<authorization::AuthorizationMessage> for AuthorizationMessage {
    fn from_proto(
        source: authorization::AuthorizationMessage,
    ) -> Result<Self, ProtoConversionError> {
        use authorization::AuthorizationMessageType::*;
        match source.message_type {
            CONNECT_REQUEST => Ok(AuthorizationMessage::ConnectRequest(FromBytes::<
                authorization::ConnectRequest,
            >::from_bytes(
                source.get_payload(),
            )?)),
            CONNECT_RESPONSE => Ok(AuthorizationMessage::ConnectResponse(FromBytes::<
                authorization::ConnectResponse,
            >::from_bytes(
                source.get_payload(),
            )?)),
            AUTHORIZE => Ok(AuthorizationMessage::Authorized(FromBytes::<
                authorization::AuthorizedMessage,
            >::from_bytes(
                source.get_payload()
            )?)),
            AUTHORIZATION_ERROR => Ok(AuthorizationMessage::AuthorizationError(FromBytes::<
                authorization::AuthorizationError,
            >::from_bytes(
                source.get_payload(),
            )?)),
            TRUST_REQUEST => Ok(AuthorizationMessage::TrustRequest(FromBytes::<
                authorization::TrustRequest,
            >::from_bytes(
                source.get_payload()
            )?)),
            AUTH_COMPLETE => Ok(AuthorizationMessage::AuthComplete(FromBytes::<
                authorization::AuthComplete,
            >::from_bytes(
                source.get_payload()
            )?)),
            AUTH_PROTOCOL_REQUEST => Ok(AuthorizationMessage::AuthProtocolRequest(FromBytes::<
                authorization::AuthProtocolRequest,
            >::from_bytes(
                source.get_payload(),
            )?)),
            AUTH_PROTOCOL_RESPONSE => Ok(AuthorizationMessage::AuthProtocolResponse(FromBytes::<
                authorization::AuthProtocolResponse,
            >::from_bytes(
                source.get_payload(),
            )?)),
            AUTH_TRUST_REQUEST => Ok(AuthorizationMessage::AuthTrustRequest(FromBytes::<
                authorization::AuthTrustRequest,
            >::from_bytes(
                source.get_payload(),
            )?)),
            AUTH_TRUST_RESPONSE => Ok(AuthorizationMessage::AuthTrustResponse(FromBytes::<
                authorization::AuthTrustResponse,
            >::from_bytes(
                source.get_payload(),
            )?)),
            AUTH_CHALLENGE_NONCE_REQUEST => Ok(AuthorizationMessage::AuthChallengeNonceRequest(
                FromBytes::<authorization::AuthChallengeNonceRequest>::from_bytes(
                    source.get_payload(),
                )?,
            )),
            AUTH_CHALLENGE_NONCE_RESPONSE => Ok(AuthorizationMessage::AuthChallengeNonceResponse(
                FromBytes::<authorization::AuthChallengeNonceResponse>::from_bytes(
                    source.get_payload(),
                )?,
            )),
            AUTH_CHALLENGE_SUBMIT_REQUEST => Ok(AuthorizationMessage::AuthChallengeSubmitRequest(
                FromBytes::<authorization::AuthChallengeSubmitRequest>::from_bytes(
                    source.get_payload(),
                )?,
            )),
            AUTH_CHALLENGE_SUBMIT_RESPONSE => {
                Ok(AuthorizationMessage::AuthChallengeSubmitResponse(
                    FromBytes::<authorization::AuthChallengeSubmitResponse>::from_bytes(
                        source.get_payload(),
                    )?,
                ))
            }
            UNSET_AUTHORIZATION_MESSAGE_TYPE => Err(ProtoConversionError::InvalidTypeError(
                "no message type was set".into(),
            )),
        }
    }
}

impl FromNative<AuthorizationMessage> for authorization::AuthorizationMessage {
    fn from_native(source: AuthorizationMessage) -> Result<Self, ProtoConversionError> {
        use authorization::AuthorizationMessageType::*;

        let mut message = authorization::AuthorizationMessage::new();
        match source {
            AuthorizationMessage::ConnectRequest(payload) => {
                message.set_message_type(CONNECT_REQUEST);
                message.set_payload(IntoBytes::<authorization::ConnectRequest>::into_bytes(
                    payload,
                )?);
            }
            AuthorizationMessage::ConnectResponse(payload) => {
                message.set_message_type(CONNECT_RESPONSE);
                message.set_payload(IntoBytes::<authorization::ConnectResponse>::into_bytes(
                    payload,
                )?);
            }
            AuthorizationMessage::Authorized(payload) => {
                message.set_message_type(AUTHORIZE);
                message.set_payload(IntoBytes::<authorization::AuthorizedMessage>::into_bytes(
                    payload,
                )?);
            }

            AuthorizationMessage::AuthorizationError(payload) => {
                message.set_message_type(AUTHORIZATION_ERROR);
                message.set_payload(IntoBytes::<authorization::AuthorizationError>::into_bytes(
                    payload,
                )?);
            }
            AuthorizationMessage::TrustRequest(payload) => {
                message.set_message_type(TRUST_REQUEST);
                message.set_payload(IntoBytes::<authorization::TrustRequest>::into_bytes(
                    payload,
                )?);
            }
            AuthorizationMessage::AuthComplete(payload) => {
                message.set_message_type(AUTH_COMPLETE);
                message.set_payload(IntoBytes::<authorization::AuthComplete>::into_bytes(
                    payload,
                )?);
            }
            AuthorizationMessage::AuthProtocolRequest(payload) => {
                message.set_message_type(AUTH_PROTOCOL_REQUEST);
                message.set_payload(IntoBytes::<authorization::AuthProtocolRequest>::into_bytes(
                    payload,
                )?);
            }
            AuthorizationMessage::AuthProtocolResponse(payload) => {
                message.set_message_type(AUTH_PROTOCOL_RESPONSE);
                message.set_payload(
                    IntoBytes::<authorization::AuthProtocolResponse>::into_bytes(payload)?,
                );
            }
            AuthorizationMessage::AuthTrustRequest(payload) => {
                message.set_message_type(AUTH_TRUST_REQUEST);
                message.set_payload(IntoBytes::<authorization::AuthTrustRequest>::into_bytes(
                    payload,
                )?);
            }
            AuthorizationMessage::AuthTrustResponse(payload) => {
                message.set_message_type(AUTH_TRUST_RESPONSE);
                message.set_payload(IntoBytes::<authorization::AuthTrustResponse>::into_bytes(
                    payload,
                )?);
            }
            AuthorizationMessage::AuthChallengeNonceRequest(payload) => {
                message.set_message_type(AUTH_CHALLENGE_NONCE_REQUEST);
                message.set_payload(
                    IntoBytes::<authorization::AuthChallengeNonceRequest>::into_bytes(payload)?,
                );
            }
            AuthorizationMessage::AuthChallengeNonceResponse(payload) => {
                message.set_message_type(AUTH_CHALLENGE_NONCE_RESPONSE);
                message.set_payload(
                    IntoBytes::<authorization::AuthChallengeNonceResponse>::into_bytes(payload)?,
                );
            }
            AuthorizationMessage::AuthChallengeSubmitRequest(payload) => {
                message.set_message_type(AUTH_CHALLENGE_SUBMIT_REQUEST);
                message.set_payload(
                    IntoBytes::<authorization::AuthChallengeSubmitRequest>::into_bytes(payload)?,
                );
            }
            AuthorizationMessage::AuthChallengeSubmitResponse(payload) => {
                message.set_message_type(AUTH_CHALLENGE_SUBMIT_RESPONSE);
                message.set_payload(
                    IntoBytes::<authorization::AuthChallengeSubmitResponse>::into_bytes(payload)?,
                );
            }
        }
        Ok(message)
    }
}