View Source GcsSignedUrl.Crypto (gcs_signed_url v0.4.6)

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

@spec sha256(String.t()) :: String.t()

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

examples

Examples

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

sign(string_to_sign, client)

View Source
@spec sign(String.t(), GcsSignedUrl.Client.t()) :: String.t()
@spec sign(String.t(), GcsSignedUrl.SignBlob.OAuthConfig.t()) ::
  {:ok, String.t()} | {:error, String.t()}

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

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..."}