@@ -8,7 +8,7 @@ use core::fmt::Formatter;
8
8
use core:: str:: FromStr ;
9
9
use std:: hash:: Hash ;
10
10
11
- use did_url :: DID as BaseDIDUrl ;
11
+ use did_url_parser :: DID as BaseDIDUrl ;
12
12
13
13
use identity_core:: common:: KeyComparable ;
14
14
@@ -111,14 +111,7 @@ impl CoreDID {
111
111
///
112
112
/// Returns `Err` if the input is not a valid [`DID`].
113
113
pub fn parse ( input : impl AsRef < str > ) -> Result < Self , Error > {
114
- let base_did_url: BaseDIDUrl = BaseDIDUrl :: parse ( input) . map_err ( Error :: from) ?;
115
- Self :: try_from_base_did ( base_did_url)
116
- }
117
-
118
- /// Try convert a [`BaseDIDUrl`] into a [`CoreDID`].
119
- fn try_from_base_did ( base_did_url : BaseDIDUrl ) -> Result < Self , Error > {
120
- Self :: check_validity ( & base_did_url) ?;
121
- Ok ( Self ( base_did_url) )
114
+ BaseDIDUrl :: parse ( input) . map ( Self ) . map_err ( Error :: from)
122
115
}
123
116
124
117
/// Set the method name of the [`DID`].
@@ -145,9 +138,23 @@ impl CoreDID {
145
138
146
139
/// Validates whether a string is a valid [`DID`] method-id.
147
140
pub fn valid_method_id ( value : & str ) -> Result < ( ) , Error > {
148
- if !value. chars ( ) . all ( is_char_method_id) {
149
- return Err ( Error :: InvalidMethodId ) ;
141
+ // if !value.chars().all(is_char_method_id) {
142
+ // return Err(Error::InvalidMethodId);
143
+ // }
144
+ let mut chars = value. chars ( ) ;
145
+ while let Some ( c) = chars. next ( ) {
146
+ match c {
147
+ '%' => {
148
+ let digits = chars. clone ( ) . take ( 2 ) . collect :: < String > ( ) ;
149
+ u8:: from_str_radix ( & digits, 16 ) . map_err ( |_| Error :: InvalidMethodId ) ?;
150
+ chars. next ( ) ;
151
+ chars. next ( ) ;
152
+ }
153
+ c if is_char_method_id ( c) => ( ) ,
154
+ _ => return Err ( Error :: InvalidMethodId ) ,
155
+ }
150
156
}
157
+
151
158
Ok ( ( ) )
152
159
}
153
160
@@ -185,7 +192,7 @@ impl TryFrom<BaseDIDUrl> for CoreDID {
185
192
type Error = Error ;
186
193
187
194
fn try_from ( base_did_url : BaseDIDUrl ) -> Result < Self , Self :: Error > {
188
- Self :: try_from_base_did ( base_did_url)
195
+ Ok ( Self ( base_did_url) )
189
196
}
190
197
}
191
198
0 commit comments