From 11262e7bbdce42d18f098549c58f8a50a82efd2d Mon Sep 17 00:00:00 2001 From: "Marc R. Hoffmann" Date: Wed, 13 Oct 2021 00:07:49 +0200 Subject: [PATCH] Fail with exception when decoding invalid image message --- src/main/java/com/mountainminds/three4j/BlobId.java | 8 -------- src/main/java/com/mountainminds/three4j/Nonce.java | 8 -------- src/main/java/com/mountainminds/three4j/PlainMessage.java | 4 ++-- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/mountainminds/three4j/BlobId.java b/src/main/java/com/mountainminds/three4j/BlobId.java index 732e993..182ef04 100644 --- a/src/main/java/com/mountainminds/three4j/BlobId.java +++ b/src/main/java/com/mountainminds/three4j/BlobId.java @@ -13,9 +13,6 @@ *******************************************************************************/ package com.mountainminds.three4j; -import java.io.IOException; -import java.io.InputStream; - /** * A 16 byte identifier for uploaded blobs. */ @@ -46,9 +43,4 @@ public static BlobId of(String hexvalue) { return of(fromHex(hexvalue)); } - static BlobId read(InputStream in) throws IOException { - var id = in.readNBytes(SIZE); - return id.length == SIZE ? of(id) : null; - } - } diff --git a/src/main/java/com/mountainminds/three4j/Nonce.java b/src/main/java/com/mountainminds/three4j/Nonce.java index b3532ff..fb9966d 100644 --- a/src/main/java/com/mountainminds/three4j/Nonce.java +++ b/src/main/java/com/mountainminds/three4j/Nonce.java @@ -13,9 +13,6 @@ *******************************************************************************/ package com.mountainminds.three4j; -import java.io.IOException; -import java.io.InputStream; - import software.pando.crypto.nacl.Bytes; /** @@ -55,9 +52,4 @@ public static Nonce random() { return of(Bytes.secureRandom(SIZE)); } - static Nonce read(InputStream in) throws IOException { - var id = in.readNBytes(SIZE); - return id.length == SIZE ? of(id) : null; - } - } diff --git a/src/main/java/com/mountainminds/three4j/PlainMessage.java b/src/main/java/com/mountainminds/three4j/PlainMessage.java index 3c195d6..aba34e3 100644 --- a/src/main/java/com/mountainminds/three4j/PlainMessage.java +++ b/src/main/java/com/mountainminds/three4j/PlainMessage.java @@ -145,9 +145,9 @@ public final static class Image extends PlainMessage { private final Nonce nonce; private Image(DataInputStream in) throws IOException { - blobId = BlobId.read(in); + blobId = BlobId.of(in.readNBytes(BlobId.SIZE)); size = in.readInt(); - nonce = Nonce.read(in); + nonce = Nonce.of(in.readNBytes(Nonce.SIZE)); } public Image(UploadedBlob blob) throws IllegalArgumentException {