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

JsonDecodeError For GenerateRandomBytesRequest #455

Open
SpadeA-Tang opened this issue Nov 28, 2023 · 4 comments
Open

JsonDecodeError For GenerateRandomBytesRequest #455

SpadeA-Tang opened this issue Nov 28, 2023 · 4 comments

Comments

@SpadeA-Tang
Copy link

It seems desearialize json is failed. The code is listed below and would you mind giving some feedbacks whether the code is inappropriate?

Err(JsonDecodeError("{\n \"data\": \"re9uM3jHgyBO55Bb5thfEc51X7qdvTFlTmYPDWU07rvSLXwKTXVQIecmyOtmjgrdH0RE+/LZ0XKNtiJKoLbm3y6+D3PWQHcmq6OgguWuQxJ23drOhypxfZdXaN2o1+xz7T31TVPqOnm3zlp8z4wtsR6cVupxgzYb5zguv5EQ73I=\",\n \"dataCrc32c\": \"589474822\"\n}\n", Error("Invalid byte 43, offset 68.", line: 2, column: 184)))

#[tokio::main]
async fn main() {
    let secret = yup_oauth2::read_authorized_user_secret(
        "/home/spadea/.config/gcloud/application_default_credentials.json",
    )
    .await
    .unwrap();

    let auth = AuthorizedUserAuthenticator::builder(secret)
        .build()
        .await
        .unwrap();

    let hub = CloudKMS::new(
        hyper::Client::builder().build(
            hyper_rustls::HttpsConnectorBuilder::new()
                .with_native_roots()
                .https_or_http()
                .enable_http1()
                .build(),
        ),
        auth,
    );

    let mut req = GenerateRandomBytesRequest::default();
    req.length_bytes = Some(128);
    req.protection_level = Some(String::from("HSM"));
    let result = hub
        .projects()
        .locations_generate_random_bytes(req, "projects/xxx/locations/xxx")
        .doit()
        .await;

    println!("{:?}", result);
}
@Byron
Copy link
Owner

Byron commented Nov 28, 2023

It's a problem with it trying to decode that JSON with data being base64 encoded into binary data, as declared in the datatype.

Its probably related to one of the many issues related to confused URL/Base64 encoding. The problem is that it's unclear how to figure out the kind of encoding just by looking at the API description, and thus far nobody was able to contribute a fix.

@SpadeA-Tang
Copy link
Author

SpadeA-Tang commented Nov 28, 2023

It's a problem with it trying to decode that JSON with data being base64 encoded into binary data, as declared in the datatype.

Its probably related to one of the many issues related to confused URL/Base64 encoding. The problem is that it's unclear how to figure out the kind of encoding just by looking at the API description, and thus far nobody was able to contribute a fix.

Thanks for the reply.

@mihirsamdarshi
Copy link
Contributor

@Byron, how would I go about adding exclusions for certain crates? google_compute1's ShieldedInstanceInitialState and other fields seem to be url-safe base64 rather than standard base64

I see the following code that maps Vec<u8> to standard or url safe base64 in the description. Should I manually change the descriptions of those fields in their respective JSON API definitions?

@Byron
Copy link
Owner

Byron commented Sep 12, 2024

Are you using the latest version from this Repository? Sometimes the latest code isn't published yet, and I remember some work that was done in this direction so I thought this decoding problem is solved once and for all.
It really looks like the fix wasn't published for all crates, definitely not for compute1.

Should I manually change the descriptions of those fields in their respective JSON API definitions?

No, these would be overwritten next time the API is updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants