Skip to content

Commit c34e903

Browse files
committed
SDK-590: Standardise Image functionality
1 parent 7654293 commit c34e903

File tree

11 files changed

+105
-16
lines changed

11 files changed

+105
-16
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,21 @@ try {
188188
Optional<YourAppUserClass> user = yourUserSearchMethod(activityDetails.getRememberMeId());
189189
if (user.isPresent()) {
190190
String rememberMeId = activityDetails.getRememberMeId();
191-
String base64Selfie = activityDetails.getBase64Selfie();
191+
192192
Attribute<Image> selfie = profile.getSelfie();
193-
Image selfieValue = selfie.getValue();
193+
if (selfie != null) {
194+
Image selfieValue = selfie.getValue();
195+
String base64Selfie = selfieValue.getBase64Content();
196+
}
194197
Attribute<String> fullName = profile.getFullName();
195198
Attribute<String> givenNames = profile.getGivenNames();
196199
Attribute<String> familyName = profile.getFamilyName();
197200
Attribute<String> phoneNumber = profile.getPhoneNumber();
198201
Attribute<String> emailAddress = profile.getEmailAddress();
199-
Boolean isAgeVerified = profile.isAgeVerified();
202+
AgeVerification over18Verification = profile.findAgeOverVerification(18);
203+
if (over18Verification != null) {
204+
boolean isAgedOver18 = over18Verification.getResult();
205+
}
200206
Attribute<Date> dateOfBirth = profile.getDateOfBirth();
201207
Attribute<String> gender = profile.getGender();
202208
Attribute<String> postalAddress = profile.getPostalAddress();

yoti-sdk-api/src/main/java/com/yoti/api/client/ActivityDetails.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ public interface ActivityDetails {
5555
String getReceiptId();
5656

5757
/**
58-
* JPEG selfie in Base64 string
59-
*
58+
* @deprecated From v2.1 onwards you should use getUserProfile().getSelfie()
59+
* JPEG selfie in Base64 string.
60+
*
6061
* @return JPEG selfie image in Base64 string format
6162
*/
63+
@Deprecated
6264
String getBase64Selfie();
6365

6466
}

yoti-sdk-api/src/main/java/com/yoti/api/client/Image.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*
66
*/
77
public interface Image {
8+
89
/**
910
* Get mime type of the content.
1011
*
@@ -18,4 +19,12 @@ public interface Image {
1819
* @return image as byte[]
1920
*/
2021
byte[] getContent();
22+
23+
/**
24+
* Base64 encoded image
25+
*
26+
* @return image as Base64 encoded String
27+
*/
28+
String getBase64Content();
29+
2130
}

yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/ImageAttributeValue.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.yoti.api.client.spi.remote;
22

3+
import static org.bouncycastle.util.encoders.Base64.toBase64String;
4+
35
import com.yoti.api.client.Image;
46

57
/**
68
* Image attribute values.
7-
*
89
*/
910
abstract class ImageAttributeValue implements Image {
1011

@@ -24,9 +25,9 @@ abstract class ImageAttributeValue implements Image {
2425
@Override
2526
public abstract byte[] getContent();
2627

27-
protected byte[] newArray(byte[] source) {
28-
byte[] result = new byte[source.length];
29-
System.arraycopy(source, 0, result, 0, source.length);
30-
return result;
28+
@Override
29+
public String getBase64Content() {
30+
return String.format("data:%s;base64,%s", getMimeType(), toBase64String(getContent()));
3131
}
32+
3233
}

yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/JpegAttributeValue.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final class JpegAttributeValue extends ImageAttributeValue {
1111
private final byte[] content;
1212

1313
public JpegAttributeValue(byte[] content) {
14-
this.content = newArray(content);
14+
this.content = content;
1515
}
1616

1717
@Override
@@ -21,6 +21,7 @@ public String getMimeType() {
2121

2222
@Override
2323
public byte[] getContent() {
24-
return newArray(content);
24+
return content.clone();
2525
}
26+
2627
}

yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/PngAttributeValue.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final class PngAttributeValue extends ImageAttributeValue {
1111
private final byte[] content;
1212

1313
public PngAttributeValue(byte[] content) {
14-
this.content = newArray(content);
14+
this.content = content;
1515
}
1616

1717
@Override
@@ -21,6 +21,7 @@ public String getMimeType() {
2121

2222
@Override
2323
public byte[] getContent() {
24-
return newArray(content);
24+
return content.clone();
2525
}
26+
2627
}

yoti-sdk-impl/src/main/java/com/yoti/api/client/spi/remote/SimpleActivityDetails.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public String getReceiptId() {
6464
}
6565

6666
@Override
67+
@Deprecated
6768
public String getBase64Selfie() {
6869
return base64Selfie;
6970
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.yoti.api.client.spi.remote;
2+
3+
import static org.junit.Assert.assertArrayEquals;
4+
import static org.junit.Assert.assertEquals;
5+
import static org.junit.Assert.assertNotSame;
6+
7+
import org.junit.Test;
8+
9+
public class JpegAttributeValueTest {
10+
11+
private static final byte[] IMAGE_DATA = new byte[] { 0, 1, 2, 3 };
12+
13+
JpegAttributeValue testObj = new JpegAttributeValue(IMAGE_DATA);
14+
15+
@Test
16+
public void shouldReturnCopyOfTheData() {
17+
byte[] result = testObj.getContent();
18+
19+
assertArrayEquals(IMAGE_DATA, result);
20+
assertNotSame(IMAGE_DATA, result);
21+
}
22+
23+
@Test
24+
public void shouldReturnBase64Selfie() {
25+
String result = testObj.getBase64Content();
26+
27+
String base64Data = Base64.getEncoder().encodeToString(IMAGE_DATA);
28+
assertEquals("data:image/jpeg;base64," + base64Data, result);
29+
}
30+
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.yoti.api.client.spi.remote;
2+
3+
import static org.junit.Assert.assertArrayEquals;
4+
import static org.junit.Assert.assertEquals;
5+
import static org.junit.Assert.assertNotSame;
6+
7+
import org.junit.Test;
8+
9+
public class PngAttributeValueTest {
10+
11+
private static final byte[] IMAGE_DATA = new byte[] { 0, 1, 2, 3 };
12+
13+
PngAttributeValue testObj = new PngAttributeValue(IMAGE_DATA);
14+
15+
@Test
16+
public void shouldReturnCopyOfTheData() {
17+
byte[] result = testObj.getContent();
18+
19+
assertArrayEquals(IMAGE_DATA, result);
20+
assertNotSame(IMAGE_DATA, result);
21+
}
22+
23+
@Test
24+
public void shouldReturnBase64Selfie() {
25+
String result = testObj.getBase64Content();
26+
27+
String base64Data = Base64.getEncoder().encodeToString(IMAGE_DATA);
28+
assertEquals("data:image/png;base64," + base64Data, result);
29+
}
30+
31+
}

yoti-sdk-impl/src/test/java/com/yoti/api/client/spi/remote/SimpleActivityDetailsTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Date;
77

88
import com.yoti.api.client.Attribute;
9+
import com.yoti.api.client.Image;
910
import com.yoti.api.client.Profile;
1011

1112
import org.bouncycastle.util.encoders.Base64;
@@ -81,13 +82,14 @@ public void shouldReturnReceiptId() {
8182

8283
@Test
8384
public void shouldReturnBase64SelfieIfSelfieSet() {
84-
Attribute selfie = new SimpleAttribute("selfie", new JpegAttributeValue(SOME_SELFIE_BYTES));
85+
Attribute<Image> selfie = new SimpleAttribute("selfie", new JpegAttributeValue(SOME_SELFIE_BYTES));
8586
SimpleProfile profile = new SimpleProfile(Collections.<Attribute<?>>singletonList(selfie));
8687

8788
SimpleActivityDetails result = new SimpleActivityDetails(REMEMBER_ME_ID, profile, APP_PROFILE, TIMESTAMP, RECEIPT_ID);
8889

8990
String expected = "data:image/jpeg;base64," + Base64.toBase64String(SOME_SELFIE_BYTES);
9091
assertEquals(expected, result.getBase64Selfie());
92+
assertEquals(selfie.getValue().getBase64Content(), result.getBase64Selfie());
9193
}
9294

9395
@Test
@@ -99,4 +101,5 @@ public void shouldReturnBlankBase64SelfieIfSelfieNotSet() {
99101

100102
assertEquals("", result.getBase64Selfie());
101103
}
104+
102105
}

0 commit comments

Comments
 (0)