feat: use tlv from commons
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package me.hatter.tools.tinyencrypt.encrypt;
|
||||
|
||||
import me.hatter.tools.commons.security.crypt.CryptOutputStream;
|
||||
import me.hatter.tools.commons.tlv.TlvUtil;
|
||||
import org.bouncycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
import java.io.*;
|
||||
@@ -24,7 +25,7 @@ public class EncryptedFile extends FilterOutputStream {
|
||||
public EncryptedFile(DataOutputStream rawOut, TinyEncryptMeta tinyEncryptMeta) throws IOException {
|
||||
super(getCryptoOutputStream(rawOut, tinyEncryptMeta));
|
||||
// this.tinyEncryptMeta = tinyEncryptMeta;
|
||||
TlvUtil.write(rawOut, TlvUtil.create(0, TinyEncryptMetaUtil.toString(tinyEncryptMeta)));
|
||||
TlvUtil.writeTlv(rawOut, TlvUtil.create(0, TinyEncryptMetaUtil.toString(tinyEncryptMeta)));
|
||||
rawOut.flush();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
package me.hatter.tools.tinyencrypt.encrypt;
|
||||
|
||||
public class Tlv {
|
||||
private int tag;
|
||||
private int length;
|
||||
private byte[] value;
|
||||
|
||||
public int getTag() {
|
||||
return tag;
|
||||
}
|
||||
|
||||
public void setTag(int tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
}
|
||||
|
||||
public byte[] getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(byte[] value) {
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package me.hatter.tools.tinyencrypt.encrypt;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class TlvUtil {
|
||||
|
||||
public static void write(DataOutputStream os, Tlv tlv) throws IOException {
|
||||
os.writeShort(tlv.getTag());
|
||||
os.writeInt(tlv.getLength());
|
||||
os.write(tlv.getValue());
|
||||
}
|
||||
|
||||
public static Tlv read(DataInputStream is) throws IOException {
|
||||
int tag = is.readShort();
|
||||
int length = is.readInt();
|
||||
byte[] bs = new byte[length];
|
||||
is.readFully(bs);
|
||||
Tlv tlv = new Tlv();
|
||||
tlv.setTag(tag);
|
||||
tlv.setLength(length);
|
||||
tlv.setValue(bs);
|
||||
return tlv;
|
||||
}
|
||||
|
||||
public static Tlv create(int tag, String value) {
|
||||
return create(tag, value.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
||||
public static Tlv create(int tag, byte[] value) {
|
||||
Tlv tlv = new Tlv();
|
||||
tlv.setTag(tag);
|
||||
tlv.setLength(value.length);
|
||||
tlv.setValue(value);
|
||||
return tlv;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user