pub struct Context<'a>(/* private fields */);Expand description
The “context” for signing and verifying messages, which is used for domain
separation of message signatures. The context can be of length
[Context::MIN_LEN..Context::MAX_LEN].
§Example
use did_simple::crypto::Context;
const CTX: Context = Context::from_bytes("MySuperCoolProtocol".as_bytes());§What is the purpose of this?
Messages signed using one context cannot be verified under a different context. This is important, because it prevents tricking someone into signing a message for one use case, and it getting reused for another use case.
§Can you give me an example of how not using a context can be bad?
Suppose that a scammer sends you a file and asks you to send it back to them signed, to prove to them that you got the message. You naively comply, only later to realize that the file you signed actually is a json message that authorizes your bank to send funds to the scammer. If you reused the same public key for sending messages as you do for authorizing bank transactions, you just got robbed.
If instead the application you were using signed that message with a “MySecureProtocolSendMessage” context, and your bank used “MySuperSafeBank”, your bank would have rejected the message signature when the scammer tried to use it to authorize a funds transfer because the two contexts don’t match.
§But I really need to not use a context for this specific case 🥺
Most of the signing algorithms’ VerifyingKeys expose an into_inner
method and reexport the cryptography crate they use. So you can just call
the relevant signing functions yourself with the lower level crate.
Implementations§
Source§impl<'a> Context<'a>
impl<'a> Context<'a>
pub const MAX_LEN: usize = 255usize
pub const MIN_LEN: usize = 4usize
Sourcepub const fn from_bytes(value: &'a [u8]) -> Self
pub const fn from_bytes(value: &'a [u8]) -> Self
Panics if value is longer than Self::MAX_LEN or is 0.