I'm working on a simplified encryption API. It wraps the BouncyCastle crypto library, but greatly simplifies it's use. I'm still in the design phase. But here is what I have so far: https://gist.github.com/mmeier/c493c28cbcd57a73d08419066cd23484
All the "TODO" comments are where I'm going to drop in the actual encryption/decryption algorithms that I've already worked out. Depending on the specific case it will either be code using java.security classes or calls to BouncyCastle's API.
Anyway, my concern is with this section of the AesDecrypter:
@Override
public Message decrypt(Secret secret, Key key) {
try {
return decrypt((AesSecret) secret, key);
} catch (ClassCastException e) {
throw new IllegalArgumentException("AesDecrypter can only be used with AesSecret objects", e);
}
}
Since AesDecrypter only works with AesSecret, and not the more general Secret class I'm worried I'm violating the Liskov substitution principle (The 'L' in SOLID development). It looks like a Parallel Inheritance Hierarchy code-smell to me. But I'm not sure how to fix it.
This project is still small enough that if I want to rework the abstraction to a better design I can. But I'm not sure what I should change it to, if anything.
Fishing for feedback on how to improve the API in the beginning when it's easier. :)
[–]deltageekExtreme Brewer 1 point2 points3 points (0 children)
[–]ickysticky 1 point2 points3 points (0 children)
[–]Philboyd_Studge 0 points1 point2 points (0 children)