Skip to content

Commit

Permalink
Merge pull request #153 from cryptimeleon/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JanBobolz authored Nov 18, 2021
2 parents 7d6fcd9 + adafc51 commit e4a2313
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Latest]

## [3.1.0]

### Added
- UUIDs can now be serialized to representation.

## [3.0.1]

Expand Down Expand Up @@ -66,7 +70,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Initial release


[Latest]: https://github.com/cryptimeleon/math/compare/v3.0.1...HEAD
[Latest]: https://github.com/cryptimeleon/math/compare/v3.1.0...HEAD
[3.1.0]: https://github.com/cryptimeleon/math/compare/v3.0.0...v3.0.1
[3.0.1]: https://github.com/cryptimeleon/math/compare/v3.0.0...v3.0.1
[3.0.0]: https://github.com/cryptimeleon/math/compare/v2.1.0...v3.0.0
[2.1.0]: https://github.com/cryptimeleon/math/compare/v2.0.0...v2.1.0
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
group = 'org.cryptimeleon'
archivesBaseName = project.name
boolean isRelease = project.hasProperty("release")
version = '3.0.3' + (isRelease ? "" : "-SNAPSHOT")
version = '3.1.0' + (isRelease ? "" : "-SNAPSHOT")

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
* For more information, consult the <a href="https://upbcuk.github.io/docs/representations.html">documentation</a>.
*/
public class ReprUtil {
static final String[] primitiveTypes = new String[] {"byte", "short", "int", "long", "float", "double", "boolean", "char"};
static Pattern methodCallSeparator = Pattern.compile("::");
/**
* Maps representation restorer identifiers to the corresponding {@code RepresentationRestorer} instances.
Expand Down Expand Up @@ -438,6 +439,9 @@ protected static RepresentationHandler getHandlerWithRestorerString(Type type, S
);
}

if (Arrays.asList(primitiveTypes).contains(type.getTypeName()))
throw new IllegalArgumentException("Cannot handle primitive type "+type.getTypeName()+". Use object wrapper types instead (like Integer or Boolean)");

throw new IllegalArgumentException("Don't know how to handle type " + type.getTypeName()
+ " using restorer String \"" + restorerString + "\"");
}
Expand All @@ -451,7 +455,6 @@ protected static RepresentationHandler getHandlerWithRestorerString(Type type, S
protected static RepresentationHandler getHandlerWithoutRestorerString(Type type) {
// For generic type we need to extract the raw type. Only for StandaloneRepresentable though, as stuff
// like list and map handling can handle generic types by themselves.
// TODO: What about DependentRepresentations?
Type rawType = type;
if (type instanceof ParameterizedType) {
rawType = ((ParameterizedType) type).getRawType();
Expand All @@ -478,8 +481,11 @@ protected static RepresentationHandler getHandlerWithoutRestorerString(Type type
return new MapRepresentationHandler(getHandlerWithoutRestorerString(keyType), getHandlerWithoutRestorerString(valueType), type);
}

if (Arrays.asList(primitiveTypes).contains(type.getTypeName()))
throw new IllegalArgumentException("Cannot handle primitive type "+type.getTypeName()+". Use object wrapper types instead (like Integer or Boolean)");

throw new IllegalArgumentException("Don't know how to handle type " + type.getTypeName()
+ " using empty restorer String (you can add one within the @Represented annotation)");
+ " using empty restorer String (you can add one within the @Represented annotation to manually specify how to recreate this type)");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import java.lang.reflect.Type;
import java.math.BigInteger;
import java.util.UUID;
import java.util.function.Function;

/**
Expand All @@ -17,7 +18,7 @@ class StandaloneRepresentationHandler implements RepresentationHandler {
// that's not null is already set (and int is auto-initialized with 0)
private static final Class<?>[] supportedTypes = new Class[] {
StandaloneRepresentable.class, BigInteger.class, Integer.class, String.class, Boolean.class,
byte[].class, Enum.class
byte[].class, UUID.class, Enum.class
};
/**
* Type of the represented object.
Expand Down Expand Up @@ -79,6 +80,10 @@ public Object deserializeFromRepresentation(Representation repr, Function<String
return repr.bytes().get();
}

if (type.isAssignableFrom(UUID.class) && repr instanceof StringRepresentation) {
return UUID.fromString(repr.str().get());
}

throw new IllegalArgumentException("Don't know how to recreate " + type.getName() + " from a "
+ repr.getClass().getName());
}
Expand Down Expand Up @@ -129,6 +134,11 @@ public Representation serializeToRepresentation(Object value) {
return new ByteArrayRepresentation(bytes);
}

if (value instanceof UUID) {
UUID uuid = (UUID) value;
return new StringRepresentation(uuid.toString());
}

throw new IllegalArgumentException("Do not know how to handle object of type " + value.getClass().getName()
+ ". You may have to add an explicit 'restorer' argument to the @Represented annotation");
}
Expand Down

0 comments on commit e4a2313

Please sign in to comment.