Skip to content

Fix up FLE support. #1550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -44,15 +45,11 @@ public DecryptingReadingConverter(CryptoManager cryptoManager) {
this.cryptoManager = cryptoManager;
}

public void setConversionService(ConversionService conversionService) {
this.conversionService = conversionService;
}

@Override
public Set<ConvertiblePair> getConvertibleTypes() {
Set<ConvertiblePair> convertiblePairs = new HashSet<>();
Class<?>[] clazzes = new Class[] { String.class, Integer.class, Long.class, Float.class, Double.class,
BigInteger.class, BigDecimal.class, Boolean.class };
BigInteger.class, BigDecimal.class, Boolean.class, Enum.class };
for (Class clazz : clazzes) {
convertiblePairs.add(new ConvertiblePair(CouchbaseDocument.class, clazz));
}
Expand All @@ -61,7 +58,8 @@ public Set<ConvertiblePair> getConvertibleTypes() {

@Override
public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) {
return source == null? null : new String(cryptoManager.decrypt(((CouchbaseDocument) source).getContent()));
return source == null ? null
: new String(cryptoManager.decrypt(((CouchbaseDocument) source).getContent()), StandardCharsets.UTF_8);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -48,7 +49,7 @@ public Set<GenericConverter.ConvertiblePair> getConvertibleTypes() {

Set<ConvertiblePair> convertiblePairs = new HashSet<>();
Class<?>[] clazzes = new Class[] { String.class, Integer.class, Long.class, Float.class, Double.class,
BigInteger.class, BigDecimal.class, Boolean.class };
BigInteger.class, BigDecimal.class, Boolean.class, Enum.class };
for (Class clazz : clazzes) {
convertiblePairs.add(new ConvertiblePair(clazz, String.class));
}
Expand All @@ -63,7 +64,7 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
com.couchbase.client.java.encryption.annotation.Encrypted ann = sourceType
.getAnnotation(com.couchbase.client.java.encryption.annotation.Encrypted.class);
Map<Object, Object> result = new HashMap<>();
result.putAll(cryptoManager.encrypt(source.toString().getBytes(), ann.encrypter()));
result.putAll(cryptoManager.encrypt(source.toString().getBytes(StandardCharsets.UTF_8), ann.encrypter()));
return new Encrypted(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ private <R> R readValue(Object value, TypeInformation type, Object parent) {
} else if (value instanceof CouchbaseList) {
return (R) readCollection(type, (CouchbaseList) value, parent);
} else {
return (R) getPotentiallyConvertedSimpleRead(value, type.getClass()); // type does not have annotations
return (R) getPotentiallyConvertedSimpleRead(value, type.getType()); // type does not have annotations
}
}

Expand Down