protectRequest
abstract suspend fun protectRequest(request: CoapMessage, peer: Endpoint): ProtectedRequest?(source)
Protects request for peer, or returns null to send it unprotected.
Null is plaintext on the wire, so an implementation returns it only where its configuration says so explicitly, such as the EDHOC resource or an opt-in like kcoap-oscore's allowUnprotected. One that is meant to protect peer and cannot, because no context or protection is installed for it, throws MessageSecurityException instead, which fails the request before anything is sent (ADR 0008).
kcoap-coap's client reports any exception from here, this one or another, as a CoapException with reason SECURITY and the exception as cause, so an implementation may let the failures of what it calls, such as a sequence-number store, pass.
Throws
when the request must be protected and cannot be.