~yujiri/libsufec-java

8693eb7926a1e185eb0b2bf46ec11ed7daf519b9 — Yujiri a month ago 9cd737e
don't use writeBytes

another thing that is android api >= 33
M src/main/java/jsufec/Crypto.java => src/main/java/jsufec/Crypto.java +6 -4
@@ 23,10 23,12 @@ public class Crypto {
		byte[] ciphertext = new byte[msgBytes.length + Box.MACBYTES];
		ls.cryptoBoxEasyAfterNm(ciphertext, msgBytes, msgBytes.length, nonce, sharedKey.getAsBytes());
		ByteArrayOutputStream output = new ByteArrayOutputStream();
		output.writeBytes(account.addr.toBytes());
		output.writeBytes(ownEph.getPublicKey().getAsBytes());
		output.writeBytes(nonce);
		output.writeBytes(ciphertext);
		byte[] addrBytes = account.addr.toBytes();
		output.write(addrBytes, 0, addrBytes.length);
		byte[] ephBytes = ownEph.getPublicKey().getAsBytes();
		output.write(ephBytes, 0, ephBytes.length);
		output.write(nonce, 0, nonce.length);
		output.write(ciphertext, 0, ciphertext.length);
		// Anonymously encrypt it
		byte[] payload = output.toByteArray();
		byte[] seal = new byte[payload.length + Box.SEALBYTES];

M src/main/java/jsufec/Message.java => src/main/java/jsufec/Message.java +5 -4
@@ 28,16 28,17 @@ public class Message {
		output.write(this.otherRecipients.size());
		for (SufecAddr addr : this.otherRecipients) {
			byte[] addrBytes = addr.toBytes();
			output.writeBytes(addrBytes);
			output.write(addrBytes, 0, addrBytes.length);
		}
		output.writeBytes(ByteConv.longToBytes(this.timestamp.getTime()));
		byte[] timestampBytes = ByteConv.longToBytes(this.timestamp.getTime());
		output.write(timestampBytes, 0, timestampBytes.length);
		output.write(this.hashes.size());
		for (MessageHash hash : this.hashes) {
			byte[] hashBytes = hash.toBytes();
			output.writeBytes(hashBytes);
			output.write(hashBytes, 0, hashBytes.length);
		}
		byte[] contentBytes = this.content.toBytes();
		output.writeBytes(contentBytes);
		output.write(contentBytes, 0, contentBytes.length);
		return output.toByteArray();
	}
	public static Message fromBytes(ByteBuffer bytes) throws InvalidMessageException {

M src/main/java/jsufec/SufecAddr.java => src/main/java/jsufec/SufecAddr.java +2 -2
@@ 33,13 33,13 @@ public class SufecAddr {
		return new SufecAddr(id, at);
	}
	public String toString() {
		return Base64.getUrlEncoder().encode(this.id.getAsBytes()) + "@" + this.at;
		return Base64.getUrlEncoder().encodeToString(this.id.getAsBytes()) + "@" + this.at;
	}
	public static SufecAddr fromString(String s) {
		int atPos = s.indexOf('@');
		return new SufecAddr(
			Key.fromBytes(Base64.getUrlDecoder().decode(s.substring(0, atPos))),
			s.substring(atPos)
			s.substring(atPos + 1)
		);
	}
}