stouset/sodium — pull request #7 by stouset (2013-06-02 00:41:21+00:00)
Title: Extract keys, nonces, and buffers into one class with secure memory semantics

Secret data such as keys, plaintexts, authenticators should be in memory
for as little time as possible. Such data should also never be be swapped
to persistent storage.

We introduce a new Sodium::Buffer which encapsulates this logic. Strings
entering the buffer have their memory copied and the original data wiped
clear (since we can't control their lifetime any other way). The copied
bytes are then locked into system memory via `mlock(2)`.

The buffer itself contains a pointer to the copied bytes. When the buffer
is garbage collected, it ensures that the bytes are zeroed. These bytes
themselves act as a frozen string, but have all but the minimum necessary
methods removed. Users needing to access this data should be very careful
to avoid copying its contents whenever possible.