ATECC508A.DataZone (atecc508a v1.4.0)

Copy Markdown View Source

This module handles operations on the data zone.

Summary

Functions

Lock the data and OTP zones.

Pad the passed in data to a multiple of 32-bytes

Pad the specified data to the exact size of the slot.

Read a slot

Return the size in bytes of the specified slot.

Write a slot in the data zone.

Write a slot in the data zone and pad to a multiple of 32-bytes

Functions

lock(transport, expected_contents)

@spec lock(ATECC508A.Transport.t(), ATECC508A.crc16()) :: :ok | {:error, atom()}

Lock the data and OTP zones.

The expected contents concatenated together for the non-private key data slots and the OTP need to be passed for a CRC calculation. They are not written by design. The logic is that this is a final chance before it's too late to check that the device is programmed correctly.

pad_to_32(data)

@spec pad_to_32(binary()) :: binary()

Pad the passed in data to a multiple of 32-bytes

This is useful when 4-byte writes aren't allowed.

pad_to_slot_size(slot, data)

@spec pad_to_slot_size(ATECC508A.Request.slot(), binary()) :: binary()

Pad the specified data to the exact size of the slot.

read(transport, slot)

@spec read(ATECC508A.Transport.t(), ATECC508A.Request.slot()) ::
  {:ok, binary()} | {:error, atom()}

Read a slot

slot_size(int)

@spec slot_size(ATECC508A.Request.slot()) :: 36 | 72 | 416

Return the size in bytes of the specified slot.

write(transport, slot, data)

@spec write(ATECC508A.Transport.t(), ATECC508A.Request.slot(), binary()) ::
  :ok | {:error, atom()}

Write a slot in the data zone.

This can use 4 byte writes if the data is not a multiple of 32 bytes. These are only allowed under some conditions. Most notably, 4-byte writes aren't allowed when the data zone is UNLOCKED.

write_padded(transport, slot, data)

@spec write_padded(ATECC508A.Transport.t(), ATECC508A.Request.slot(), binary()) ::
  :ok | {:error, atom()}

Write a slot in the data zone and pad to a multiple of 32-bytes

This is useful to get around 32-byte write limitations. The padded bytes are set to 0.