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

Add MiscellaneousSelectVerifier for ReportBody verification #22

Merged
merged 1 commit into from
Mar 4, 2023

Conversation

nick-mobilecoin
Copy link
Collaborator

No description provided.

@codecov
Copy link

codecov bot commented Feb 28, 2023

Codecov Report

Merging #22 (2a492d8) into nick/isv_version (f430127) will increase coverage by 0.58%.
The diff coverage is 97.22%.

@@                 Coverage Diff                  @@
##           nick/isv_version      #22      +/-   ##
====================================================
+ Coverage             91.86%   92.44%   +0.58%     
====================================================
  Files                     2        2              
  Lines                   295      331      +36     
====================================================
+ Hits                    271      306      +35     
- Misses                   24       25       +1     
Impacted Files Coverage Δ
verifier/src/lib.rs 85.29% <ø> (ø)
verifier/src/report_body.rs 97.43% <97.22%> (-0.05%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Contributor

@jcape jcape left a comment

Choose a reason for hiding this comment

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

This LGTM, but reading through all these, can they be collapsed into either a macro or a blanket impl over generics?

e.g. the blanket impls version would look something like:

/// A marker trait supporting objects which should be verified with ct_eq()

trait IntoVerificationError {
    fn into_verification_error(expected: Self, actual: Self) -> VerificationError;
}

trait VerifiedWithCtEq: ConstantTimeEq + IntoVerificationError {}

// this can be macro-ized.
impl IntoVerificationError for MiscellaneousSelect {
    fn into_verification_error(expected, Self, actual: Self) -> VerificationError {
        VerificationError::MiscellaneousSelectMismatch {
            expected,
            actual
        }
    }
}
impl VerifiedWithCtEq for MiscellaneousSelect {}

// etc.
impl VerifiedWithCtEq for ConfigId {}
impl VerifiedWithCtEq for ExtProdId {}

/// Equality verifier
pub struct EqualityVerifier<T: VerifiedWithEq + Clone> {
    expected: T
}

impl<T: VerifiedWithCtEq, E: Accessor<T>> Verifier<E> for EqualityVerifier<T> {
    type Error = VerificationError;

    fn verify(&self, evidence: &E) -> CtOption<Self::Error> {
        let expected = self.expected.clone();
        let actual = evidence.get();

        let is_eq = expected.ct_eq(actual);
        CtOption::new(
            T::into_verification_error(expected, actual),
            !is_eq
        )
    }
}

Whereas a macro would just macroize the Verifier impl at the end, but would require having everything be visible from the macro.

@nick-mobilecoin
Copy link
Collaborator Author

bump @varsha888 due to restack

@nick-mobilecoin
Copy link
Collaborator Author

nick-mobilecoin commented Mar 2, 2023

This LGTM, but reading through all these, can they be collapsed into either a macro or a blanket impl over generics?

Will work on this as a follow on PR on top of #26 or after all of them are merged, added task to #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Medium-sized PRs
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants