@@ -103,13 +103,7 @@ pub enum AttributesError {
103103pub enum ConversionsError {
104104 /// Ssh key error
105105 #[ error( transparent) ]
106- SshKey ( #[ from] ssh_key:: Error ) ,
107- /// Ssh key label error
108- #[ error( transparent) ]
109- SshKeyLabel ( #[ from] ssh_encoding:: LabelError ) ,
110- /// Ssh encoding error
111- #[ error( transparent) ]
112- SshEncoding ( #[ from] ssh_encoding:: Error ) ,
106+ Ssh ( #[ from] SshErrors ) ,
113107 /// Public key operation failure
114108 #[ error( "Public key error: {0}" ) ]
115109 PublicKeyFailure ( String ) ,
@@ -124,6 +118,49 @@ pub enum ConversionsError {
124118 UnsupportedCodec ( multicodec:: Codec ) ,
125119}
126120
121+ /// SSH Encoding Errors that cannot be handled by thiserror since they may not use the std feature
122+ /// in the case of wasm32 target.
123+ #[ derive( Clone , Debug ) ]
124+ pub enum SshErrors {
125+ /// Error from [ssh_key::Error]
126+ Key ( ssh_key:: Error ) ,
127+ /// Invalid label from [ssh_encoding::LabelError]
128+ KeyLabel ( ssh_encoding:: LabelError ) ,
129+ /// Unexpected trailing data at end of message from [ssh_encoding::Error]
130+ Encoding ( ssh_encoding:: Error ) ,
131+ }
132+
133+ /// Impl Display for EncodingError
134+ impl std:: fmt:: Display for SshErrors {
135+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
136+ match self {
137+ SshErrors :: Key ( err) => write ! ( f, "{}" , err) ,
138+ SshErrors :: KeyLabel ( err) => write ! ( f, "{}" , err) ,
139+ SshErrors :: Encoding ( err) => write ! ( f, "{}" , err) ,
140+ }
141+ }
142+ }
143+
144+ impl std:: error:: Error for SshErrors { }
145+
146+ impl From < ssh_encoding:: Error > for SshErrors {
147+ fn from ( err : ssh_encoding:: Error ) -> Self {
148+ SshErrors :: Encoding ( err)
149+ }
150+ }
151+
152+ impl From < ssh_key:: Error > for SshErrors {
153+ fn from ( err : ssh_key:: Error ) -> Self {
154+ SshErrors :: Key ( err)
155+ }
156+ }
157+
158+ impl From < ssh_encoding:: LabelError > for SshErrors {
159+ fn from ( err : ssh_encoding:: LabelError ) -> Self {
160+ SshErrors :: KeyLabel ( err)
161+ }
162+ }
163+
127164/// Cipher errors created by this library
128165#[ derive( Clone , Debug , thiserror:: Error ) ]
129166#[ non_exhaustive]
0 commit comments