Add a key importer for plain text aegis databases

pull/41/head
Alexander Bakker 7 years ago
parent 642784fe9d
commit 107ca18187

@ -16,7 +16,7 @@ public class KeyInfo implements Serializable {
private int _digits = 6;
private int _period = 30;
public String getURL() throws Exception {
public String getURL() {
Uri.Builder builder = new Uri.Builder();
builder.scheme("otpauth");
builder.authority(_type);

@ -1,5 +1,6 @@
package me.impy.aegis.db;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
@ -17,7 +18,7 @@ public class DatabaseEntry implements Serializable {
_info = info;
}
public JSONObject serialize() throws Exception {
public JSONObject serialize() throws JSONException {
JSONObject obj = new JSONObject();
obj.put("id", _id);
obj.put("name", _name);

@ -0,0 +1,30 @@
package me.impy.aegis.ext;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.List;
import me.impy.aegis.db.Database;
import me.impy.aegis.db.DatabaseEntry;
public class AegisImporter extends KeyConverter {
public AegisImporter(InputStream stream) {
super(stream);
}
@Override
public List<DatabaseEntry> convert() throws Exception {
int read;
byte[] buffer = new byte[4096];
ByteArrayOutputStream stream = new ByteArrayOutputStream();
while ((read = _stream.read(buffer, 0, buffer.length)) != -1) {
stream.write(buffer, 0, read);
}
byte[] bytes = stream.toByteArray();
Database db = new Database();
db.deserialize(bytes);
return db.getKeys();
}
}
Loading…
Cancel
Save