GcsSignedUrl.Crypto (gcs_signed_url v0.4.3) View Source

Provides crypto functionality like signing and hashing strings.

Link to this section Summary

Functions

Hashed the given string using sha256 algorithm and encode it as lowercase hex string.

If you pass a %GcsSignedUrl.Client{} as second argument, this function signs the given string with the given client's private key.

Link to this section Functions

Specs

sha256(String.t()) :: String.t()

Hashed the given string using sha256 algorithm and encode it as lowercase hex string.

Examples

iex> GcsSignedUrl.Crypto.sha256("foo")
"1fad6186e41f577a37f56589..."
Link to this function

sign(string_to_sign, client)

View Source

Specs

If you pass a %GcsSignedUrl.Client{} as second argument, this function signs the given string with the given client's private key.

If you pass a %GcsSignedUrl.SignBlob.OAuthConfig{} as second argument, this function signs the given string using the signBlob REST API.

(see https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/signBlob)

Examples

iex> GcsSignedUrl.Crypto.sign("foo", %GcsSignedUrl.Client{private_key: "-----BEGIN RSA PRIVATE KEY-----..."})
"..."

iex> GcsSignedUrl.Crypto.sign("foo", %GcsSignedUrl.SignBlob.OAuthConfig{access_token: "..."})
{:ok, "1fad6186e41f577a37f56589..."}