stixex v0.1.2 StixEx.Types.Hashes View Source

The Hashes type represents 1 or more cryptographic hashes, as a special set of key/value pairs.

Accordingly, the name of each hashing algorithm MUST be specified as a key in the dictionary and MUST identify the name of the hashing algorithm used to generate the corresponding value.

This name SHOULD either be one of the values defined in the hash-algorithm-ov OR a custom value prepended with “x_” (e.g., “x_custom_hash”).

Link to this section Summary

Functions

Assert that all keys match what we expect

Dumps the given term into an Ecto native type

Loads the given term into a custom type

Returns the underlying schema type for the custom type

Link to this section Functions

Assert that all keys match what we expect

iex> StixEx.Types.Hashes.cast(%{"SHA-1": "asdf"}) {:ok, %{"SHA-1": "asdf"}}

iex> StixEx.Types.Hashes.cast(%{"x_custom_hash": "abc"}) {:ok, %{"x_custom_hash": "abc"}}

iex> StixEx.Types.Hashes.cast(%{"ohno-hash": "abc"}) :error

Dumps the given term into an Ecto native type.

This callback is called with any term that was stored in the struct and it needs to validate them and convert it to an Ecto native type.

Callback implementation for Ecto.Type.dump/1.

Loads the given term into a custom type.

This callback is called when loading data from the database and receive an Ecto native type. It can return any type, as long as the dump/1 function is able to convert the returned value back into an Ecto native type.

Callback implementation for Ecto.Type.load/1.

Returns the underlying schema type for the custom type.

For example, if you want to provide your own date structures, the type function should return :date.

Note this function is not required to return Ecto primitive types, the type is only required to be known by the adapter.

Callback implementation for Ecto.Type.type/0.