bakery: more intelligent prefix handling for PublicKeyRing

The previous string-prefix-based handling was seriously flawed.