RustCrypto / formats

Cryptography-related format encoders/decoders: DER, PEM, PKCS, PKIX
228 stars 121 forks source link

der: have `Reader::peek*` methods take `&mut self` #1418

Closed tarcieri closed 1 month ago

tarcieri commented 1 month ago

Right now PemReader uses interior mutability via RefCell, because peeking might involve filling an internal peek buffer (i.e. decoding the Base64 in a PEM document).

Rather than trying to hide the fact we're potentially modifying internal buffers (but not the cursor/position) when peeking, this changes the methods to explicitly accept &mut self, and with that change eliminates all usages of RefCell.

This change appears to have no practical drawbacks, since peeking always occurs during the decoding process where we need mutable access to the reader anyway.