Skip to content

Commit

Permalink
fixed issue where silentDecryptionFailure=true still failed on non-en…
Browse files Browse the repository at this point in the history
…crypted field
  • Loading branch information
agoston committed Mar 23, 2021
1 parent dd4f094 commit 7ce9d99
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public Object apply(Object o) {

if (o instanceof Binary) data = ((Binary) o).getData();
else if (o instanceof byte[]) data = (byte[]) o;
else throw new IllegalStateException("Got " + o.getClass() + ", expected: Binary or byte[]");
else if (!silentDecryptionFailure) throw new IllegalStateException("Got " + o.getClass() + ", expected: Binary or byte[]");
else return o; // e.g. crypted field not encrypted, other issues - we do our best

try {
byte[] serialized = cryptVault.decrypt((data));
Expand Down Expand Up @@ -66,7 +67,6 @@ public BSONCallback createBSONCallback() {

class Encoder extends BasicBSONEncoder implements Function<Object, Object> {
public Object apply(Object o) {
// FIXME: switch to BsonDocumentWriter
// we need to put even BSONObject and BSONList in a wrapping object before serialization, otherwise the type information is not encoded.
// this is not particularly effective, however, it is the same that mongo driver itself uses on the wire, so it has 100% compatibility w.r.t de/serialization
byte[] serialized = encode(new BasicBSONObject("", o));
Expand Down

0 comments on commit 7ce9d99

Please sign in to comment.