The Problem
We have a CredentialManager implementation which can be in two states: locked or unlocked.
When the manager is locked, it can be unlocked with the unlock(...) method. Now unlocked, the set(...) and get(...) methods can be performed on the manager. Also, it can be locked again using the lock() method.
let mut pw = CredentialManager::new();
pw.unlock("pssst");
pw.set("foo", "bar");
let val = pw.get("foo");
pw.lock();
But with the current implementation, on a locked manager, the get and set could be performed which would result in erroneous results.
let mut pw = CredentialManager::new();
pw.set("foo", "bar"); // -> 💥
Also, nothing prevents us from unlocking an already unlocked manager as well as locking an already locked manager.
let mut pw = CredentialManager::new();
pw.unlock("pssst");
pw.unlock("pssst"); // -> 💥
let mut pw = CredentialManager::new();
pw.lock(); // -> 💥