Package-level declarations

Types

Link copied to clipboard
class ByteArrayBuilder(initialCapacity: Int = 64)

A growable byte buffer for encoders. Methods chain; toByteArray returns a copy of what was written.

Link copied to clipboard
@RequiresOptIn(message = "An SPI with no implementation yet: its shape may change when the first one lands.", level = RequiresOptIn.Level.ERROR)
annotation class ExperimentalKcoapApi

Marks a published SPI that nothing implements yet, such as DatagramSecurity, which the DTLS engine will implement. Its shape may still change when the first implementation lands; the marker is removed in the same release as that implementation and its interop tests.

Link copied to clipboard
object Hex

Lower-case hexadecimal encoding, used by logs, test vectors and toString() of byte-carrying types.

Link copied to clipboard
@RequiresOptIn(message = "kcoap's internal plumbing between its modules: it may change or disappear in any release.", level = RequiresOptIn.Level.ERROR)
annotation class InternalKcoapApi

Marks plumbing that kcoap's modules share with each other, such as byte builders and option codecs. It is public only because Kotlin has no visibility between modules of one library: it may change or disappear in any release, and it is left out of the published ABI dumps.

Link copied to clipboard

The root of the exceptions kcoap's facades fail with at runtime: what went wrong with the peer, the network, message security, the protocol or the endpoint's lifecycle, as opposed to a mistake of the caller, which is an IllegalArgumentException or IllegalStateException. Each protocol has its own subtype, which says what failed and carries what that protocol needs to answer:

Functions

Link copied to clipboard

Compares two arrays in time that depends only on their lengths, never on where they differ. Use it for every comparison of a MAC, tag or other secret-derived value.

Link copied to clipboard

"0a ff".hexToBytes() contentEquals byteArrayOf(0x0a, 0xff).

Link copied to clipboard

Big-endian unsigned encoding of value in the fewest bytes; zero encodes as an empty array.

Link copied to clipboard
fun ByteArray.readUnsigned(offset: Int = 0, length: Int = size - offset): Long

Reads length bytes at offset as a big-endian unsigned number. At most 7 bytes, so it fits a Long.

Link copied to clipboard

byteArrayOf(0x0a, 0xff).toHex() == "0aff".

Link copied to clipboard

Overwrites the array with zeros, for key material that is no longer needed.