Asset OTA

AssetHash

Since 5.5.0:

Class to hold a hash (digest) of data. Currently only uses SHA-256, but could be extended to use other hash types in the future.

This class does not calculate the hash, it merely is a container that holds the hash value and type of hash, and implements useful comparison methods.

When using ApplicationAsset you can get the SHA-256 hash for an asset using the hash() method.

Constructor - AssetHash

// PROTOTYPES
AssetHash();
AssetHash(const char* hash, size_t length, Type type = Type::DEFAULT);
AssetHash(const uint8_t* hash, size_t length, Type type = Type::DEFAULT);
AssetHash(const Buffer& hash, Type type = Type::DEFAULT);
AssetHash(const AssetHash& other) = default;
AssetHash(AssetHash&& other) = default;

You will typically not construct one of these as the class is instantiated by ApplicationAsset. However you can construct your own if desired. Note that the this class does not actually do the hashing; it's a container to hold the pre-hashed value.

type() - AssetHash

// PROTOTYPE
Type type() const;

Returns the type:

  • AssetHash::Type::INVALID (-1) - Invalid, occurs when using the default constructor
  • AssetHash::Type::SHA256 (0) - SHA-256 (32 byte hash)
  • AssetHash::Type::DEFAULT - Alias for AssetHash::Type::SHA256

hash() - AssetHash

// PROTOTYPE
const Buffer& hash() const;

Returns a reference to the binary representation of the hash.

In most cases, you will use toString() or the equality test instead of this method.

isValid() - AssetHash

// PROTOTYPE
bool isValid() const;

Returns true if the hash type is set and is not empty.

toString() - AssetHash

// PROTOTYPE
String toString() const;

Returns a text representation of the hash. For SHA-256, this is 64 lowercase hexadecimal (0-9, a-f) characters.

operator==() - AssetHash

// PROTOTYPE
bool operator==(const AssetHash& other) const;

Returns true if two hashes are equal.

operator!=() - AssetHash

// PROTOTYPE
bool operator!=(const AssetHash& other) const;

Returns true if two hashes are not equal.