1 | /** | |
2 | Copyright 2017 Carlos Macasaet | |
3 | ||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | you may not use this file except in compliance with the License. | |
6 | You may obtain a copy of the License at | |
7 | ||
8 | http://www.apache.org/licenses/LICENSE-2.0 | |
9 | ||
10 | Unless required by applicable law or agreed to in writing, software | |
11 | distributed under the License is distributed on an "AS IS" BASIS, | |
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | See the License for the specific language governing permissions and | |
14 | limitations under the License. | |
15 | */ | |
16 | package com.macasaet.fernet; | |
17 | ||
18 | import static com.macasaet.fernet.Constants.charset; | |
19 | ||
20 | import java.nio.charset.Charset; | |
21 | import java.util.function.Function; | |
22 | ||
23 | /** | |
24 | * A {@link Validator} for payloads that represent objects as Strings (e.g. JSON or XML). This validator converts the | |
25 | * payload to a String then delegates to {@link #getStringTransformer()} to convert that String to an object. If the | |
26 | * deserialisation library you use already provides a way to convert binary into objects, then you can use | |
27 | * {@link Validator} directly instead. | |
28 | * | |
29 | * <p>Copyright © 2017 Carlos Macasaet.</p> | |
30 | * | |
31 | * @author Carlos Macasaet | |
32 | * @param <T> | |
33 | * The type of the payload. The Fernet token encodes the payload in binary. The type T should be a domain | |
34 | * object or data transfer object representation of that data. | |
35 | */ | |
36 | public interface StringObjectValidator<T> extends Validator<T> { | |
37 | ||
38 | default Charset getCharset() { | |
39 |
1
1. getCharset : mutated return of Object value for com/macasaet/fernet/StringObjectValidator::getCharset to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return charset; |
40 | } | |
41 | ||
42 | /** | |
43 | * Override this to specify an alternative way to convert binary data into a String. The default implementation uses | |
44 | * the UTF-8 character set. | |
45 | * | |
46 | * @return a method for converting a byte array into a String | |
47 | */ | |
48 | default Function<byte[], String> getStringCreator() { | |
49 |
2
1. getStringCreator : mutated return of Object value for com/macasaet/fernet/StringObjectValidator::getStringCreator to ( if (x != null) null else throw new RuntimeException ) → KILLED 2. lambda$getStringCreator$0 : mutated return of Object value for com/macasaet/fernet/StringObjectValidator::lambda$getStringCreator$0 to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return bytes -> new String(bytes, getCharset()); |
50 | } | |
51 | ||
52 | @SuppressWarnings("PMD.LawOfDemeter") | |
53 | default Function<byte[], T> getTransformer() { | |
54 |
1
1. getTransformer : mutated return of Object value for com/macasaet/fernet/StringObjectValidator::getTransformer to ( if (x != null) null else throw new RuntimeException ) → KILLED |
return getStringCreator().andThen(getStringTransformer()); |
55 | } | |
56 | ||
57 | /** | |
58 | * Plug in your String deserialisation method here. | |
59 | * | |
60 | * @return a method for converting a String into an Object. | |
61 | */ | |
62 | Function<String, T> getStringTransformer(); | |
63 | ||
64 | } | |
Mutations | ||
39 |
1.1 |
|
49 |
1.1 2.2 |
|
54 |
1.1 |