5 5 | /// The actual event message
|
6 6 | pub message: T,
|
7 7 | /// Signature information if the message was signed
|
8 8 | pub signature: ::std::option::Option<crate::sigv4_event_stream::SignatureInfo>,
|
9 9 | }
|
10 10 |
|
11 11 | /// Error wrapper for signed event stream errors
|
12 12 | #[derive(Debug)]
|
13 13 | pub enum SignedEventError<E> {
|
14 14 | /// Error from the underlying event stream
|
15 - | Event(E),
|
15 + | Event {
|
16 + | /// The error from the underlying event stream
|
17 + | error: E,
|
18 + | /// Signature information if the message was signed
|
19 + | signature: ::std::option::Option<crate::sigv4_event_stream::SignatureInfo>,
|
20 + | },
|
16 21 | /// Error extracting signed message
|
17 22 | InvalidSignedEvent(crate::sigv4_event_stream::ExtractionError),
|
18 23 | }
|
19 24 |
|
20 25 | impl<E> From<E> for SignedEventError<E> {
|
21 26 | fn from(err: E) -> Self {
|
22 - | SignedEventError::Event(err)
|
27 + | SignedEventError::Event {
|
28 + | error: err,
|
29 + | signature: None,
|
30 + | }
|
23 31 | }
|
24 32 | }
|
25 33 |
|
26 34 | /// Information extracted from a signed event stream message
|
27 35 | #[non_exhaustive]
|
28 36 | #[derive(Debug, Clone)]
|
29 37 | pub struct SignatureInfo {
|
30 38 | /// The chunk signature bytes from the `:chunk-signature` header
|
31 - | pub chunk_signature: Vec<u8>,
|
39 + | pub chunk_signature: ::std::vec::Vec<u8>,
|
32 40 | /// The timestamp from the `:date` header
|
33 41 | pub timestamp: ::std::time::SystemTime,
|
34 42 | }
|
35 43 |
|
36 44 | /// Error type for signed message extraction operations
|
37 45 | #[non_exhaustive]
|
38 46 | #[derive(Debug)]
|
39 47 | pub enum ExtractionError {
|
40 48 | /// The payload could not be decoded as a valid message
|
41 49 | #[non_exhaustive]
|
42 50 | InvalidPayload {
|
43 51 | error: ::aws_smithy_eventstream::error::Error,
|
44 52 | },
|
45 53 | /// The timestamp header is missing or has an invalid format
|
46 54 | #[non_exhaustive]
|
47 55 | InvalidTimestamp,
|
48 56 | }
|
49 57 |
|
50 58 | /// Unmarshaller wrapper that handles SigV4 signed event stream messages
|
51 59 | #[derive(Debug)]
|
52 60 | pub struct SigV4Unmarshaller<T> {
|
53 61 | inner: T,
|
54 62 | }
|
55 63 |
|
56 64 | impl<T> SigV4Unmarshaller<T> {
|
57 65 | pub fn new(inner: T) -> Self {
|
58 66 | Self { inner }
|
59 67 | }
|
60 68 | }
|
61 69 |
|
62 70 | impl<T> ::aws_smithy_eventstream::frame::UnmarshallMessage for SigV4Unmarshaller<T>
|
63 71 | where
|
64 72 | T: ::aws_smithy_eventstream::frame::UnmarshallMessage,
|
65 73 | {
|
66 74 | type Output = crate::sigv4_event_stream::SignedEvent<T::Output>;
|
67 75 | type Error = crate::sigv4_event_stream::SignedEventError<T::Error>;
|
68 76 |
|
69 77 | fn unmarshall(
|
70 78 | &self,
|
71 79 | message: &::aws_smithy_types::event_stream::Message,
|
72 80 | ) -> ::std::result::Result<
|
73 81 | ::aws_smithy_eventstream::frame::UnmarshalledMessage<Self::Output, Self::Error>,
|
74 82 | ::aws_smithy_eventstream::error::Error,
|
75 83 | > {
|
76 84 | // First, try to extract the signed message
|
77 85 | match crate::sigv4_event_stream::extract_signed_message(message) {
|
78 86 | Ok(MaybeSignedMessage::Signed {
|
79 87 | message: inner_message,
|
80 88 | signature,
|
81 89 | }) => {
|
82 90 | // Process the inner message with the base unmarshaller
|
83 91 | match self.inner.unmarshall(&inner_message) {
|
84 92 | Ok(unmarshalled) => match unmarshalled {
|
85 93 | ::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(event) => {
|
86 94 | Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(
|
87 95 | crate::sigv4_event_stream::SignedEvent {
|
88 96 | message: event,
|
89 - | signature: Some(signature),
|
97 + | signature: Some(signature.clone()),
|
90 98 | },
|
91 99 | ))
|
92 100 | }
|
93 101 | ::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(err) => {
|
94 102 | Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(
|
95 - | crate::sigv4_event_stream::SignedEventError::Event(err),
|
103 + | crate::sigv4_event_stream::SignedEventError::Event {
|
104 + | error: err,
|
105 + | signature: Some(signature),
|
106 + | },
|
96 107 | ))
|
97 108 | }
|
98 109 | },
|
99 110 | Err(err) => Err(err),
|
100 111 | }
|
101 112 | }
|
102 113 | Ok(MaybeSignedMessage::Unsigned) => {
|
103 114 | // Process unsigned message directly
|
104 115 | match self.inner.unmarshall(message) {
|
105 116 | Ok(unmarshalled) => match unmarshalled {
|
106 117 | ::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(event) => {
|
107 118 | Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Event(
|
108 119 | crate::sigv4_event_stream::SignedEvent {
|
109 120 | message: event,
|
110 121 | signature: None,
|
111 122 | },
|
112 123 | ))
|
113 124 | }
|
114 125 | ::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(err) => {
|
115 126 | Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(
|
116 - | crate::sigv4_event_stream::SignedEventError::Event(err),
|
127 + | crate::sigv4_event_stream::SignedEventError::Event {
|
128 + | error: err,
|
129 + | signature: None,
|
130 + | },
|
117 131 | ))
|
118 132 | }
|
119 133 | },
|
120 134 | Err(err) => Err(err),
|
121 135 | }
|
122 136 | }
|
123 137 | Err(extraction_err) => Ok(::aws_smithy_eventstream::frame::UnmarshalledMessage::Error(
|
124 138 | crate::sigv4_event_stream::SignedEventError::InvalidSignedEvent(extraction_err),
|
125 139 | )),
|
126 140 | }
|