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

Unable to mock a TimeStampReponse #18

Closed
koen-serry opened this issue Aug 14, 2023 · 2 comments
Closed

Unable to mock a TimeStampReponse #18

koen-serry opened this issue Aug 14, 2023 · 2 comments

Comments

@koen-serry
Copy link

Hi, i'm trying to create a sample TimeStampResp, but for some reason the const OID_CONTENT_TYPE_TST_INFO cannot be assigned to the content_type of the TimeStampToken.

It fails on the content_type, it's probably a stupid thing but I can't get it to work. Even assigning it to a temp Oid via Oid::<Bytes>::from(OID_CONTENT_TYPE_TST_INFO.0); didn't work. It seems that content_type and the const are of a different type but I'm unable to grasp why that is or how to convert one into the other.

let tst_response = TimeStampResp {
      status: PkiStatusInfo {
          status: PkiStatus::Granted,
          status_string: None,
          fail_info: None,
      },
      time_stamp_token: Some(
          TimeStampToken {
              content_type: OID_CONTENT_TYPE_TST_INFO, <-- expected struct `Bytes`, found `&[u8]`
              content: tst_capture,
          }
      ),
  };```
@indygreg
Copy link
Owner

The bcder crate can be very finicky.

You can try using the Constructed::decode() function from bcder to materialize a deserialized ASN.1 value from its bytes. In this case you want to feed in the raw bytes of an OID and parse into an Oid instance.

This is super inefficient but it seems to be one of the few ways you can coerce types in bcder.

You could also try Oid(Bytes::copy_from_slice(...)) to initialize an Oid from a Bytes created from an &[u8]. I do this a bunch in my apple-codesign crate.

@koen-serry
Copy link
Author

Yes, the Oid(Bytes::copy_from_slice(OID_CONTENT_TYPE_TST_INFO.0)) did it. Thanks!

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

No branches or pull requests

2 participants