open-keychain/open-keychain — pull request #608 by Valodim (2014-05-04 16:31:43+00:00)
Title: BouncyCastle abstraction layer approach

This is my attempt at a wrapping layer between bouncycastle objects and android code. Putting this up here for discussion rather than merging, it's not quite finished and severely missing documentation and testing.

So what I'm going for here is that ProviderHelper should provide no more methods to get PGP objects, but rather Cached{Public,Secret}KeyRings. Both of those extend a base class and contain their unified attributes in addition to the key data itself. Pretty much all PgpKeyHelper methods moved into these classes, some make use of cached info although most don't.

The parts that makes use of cached data are usually operations that require verification of certificates, ie the primary user id, verification, and information about subkeys ("which non-revoked non-expired subkeys which can sign data should I use"). While this avoids a lot of key operations, it also introduces significant overhead for some scenarios (e.g. "fetch secret key and see if it requires a passphrase"), and I'm not sure yet if I want to keep it this way. These aspects are not coded in stone though and can be fine tuned later without too much trouble, so I'm leaving it at this status quo for now.

There are also Uncached* objects. These purely contain data that is used to display info about them and get them in the database at some point. Since OK has no notion of "on the fly" operations, all operations that actually do something non-informational (encrypt, decrypt, sign, ...) are in the Cached* classes exclusively. This leads to fairly natural data flows, for example CachedSecretKeyRing.changePassphrase() returns an UncachedSecretKeyRing which is not useful for much other than writing it back into the database.

This is a WIP still, most notably the saveKeyRing methods are still using bc objects. There are some parts that don't work quite so naturally yet, and the inheritance graph is kinda weird in some places (UncachedPublicKey -> CachedPublicKey -> CachedSecretKey, but also UncachedPublicKey -> UncachedSecretKey)