Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix verkey expansion #104

Merged

Conversation

c2bo
Copy link
Member

@c2bo c2bo commented Oct 25, 2022

Fixes a bug that was taken over from the initial resolver prototype, see IDunion/indy-did-resolver#26 for more details.

@c2bo c2bo force-pushed the fix/expand-verkey branch from 77c6814 to 007c3ff Compare October 25, 2022 09:07
@c2bo
Copy link
Member Author

c2bo commented Oct 25, 2022

failing step in GHA should be fixed by #105

Copy link
Contributor

@berendsliedrecht berendsliedrecht left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not too familiar with the specific implementation so my review is mainly about the code.

Comment on lines 179 to 183
let expanded_verkey = expand_verkey_indy(id, verkey);
if expanded_verkey.is_err() {
return verkey.to_string();
}
return expanded_verkey.unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a match would be cleaner here:

Suggested change
let expanded_verkey = expand_verkey_indy(id, verkey);
if expanded_verkey.is_err() {
return verkey.to_string();
}
return expanded_verkey.unwrap();
match expand_verkey_indy(id, verkey) {
Ok(key) => key,
Err(_) => verkey.to_string()
}

returning with a &str would make it even terser though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I fully agree - looking at your code feels like looking at rust code - mine feels like Go :D

Copy link
Contributor

@berendsliedrecht berendsliedrecht Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expand_verkey_indy(id, verkey).unwrap_or(verkey.to_string())

Would probably work as well now that I think about it.

libindy_vdr/src/resolver/did_document.rs Outdated Show resolved Hide resolved
let (key, key_type) = if verkey.contains(":") {
let vec: Vec<&str> = verkey.split(":").collect();
match vec.len() {
0 | 1 => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You check here for a length of 0 or 1, but you never check the total element count. In the match case below vec[vec.len() - 1] is called which might be the 99th element. I think a length check here would be a good addition.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change that whole key_type part to expect ecactly 2 outputs and error on anything else - the indy-sdk implementation kinda expects the same.

Signed-off-by: Christian Bormann <ChristianCarl.Bormann@de.bosch.com>
@c2bo c2bo force-pushed the fix/expand-verkey branch from 007c3ff to f2483cf Compare October 27, 2022 12:54
@c2bo c2bo requested a review from berendsliedrecht October 27, 2022 13:55
Copy link
Member

@andrewwhitehead andrewwhitehead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still a few odd code patterns for Rust but I think the behaviour is correct, and it can be cleaned up a bit later.

@andrewwhitehead andrewwhitehead merged commit f1345bb into hyperledger:did-indy Nov 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants