mirror of
https://github.com/beemdevelopment/Aegis.git
synced 2025-05-14 14:02:49 +00:00
Add a key importer for plain text aegis databases
This commit is contained in:
parent
642784fe9d
commit
107ca18187
3 changed files with 33 additions and 2 deletions
|
@ -16,7 +16,7 @@ public class KeyInfo implements Serializable {
|
||||||
private int _digits = 6;
|
private int _digits = 6;
|
||||||
private int _period = 30;
|
private int _period = 30;
|
||||||
|
|
||||||
public String getURL() throws Exception {
|
public String getURL() {
|
||||||
Uri.Builder builder = new Uri.Builder();
|
Uri.Builder builder = new Uri.Builder();
|
||||||
builder.scheme("otpauth");
|
builder.scheme("otpauth");
|
||||||
builder.authority(_type);
|
builder.authority(_type);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package me.impy.aegis.db;
|
package me.impy.aegis.db;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -17,7 +18,7 @@ public class DatabaseEntry implements Serializable {
|
||||||
_info = info;
|
_info = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject serialize() throws Exception {
|
public JSONObject serialize() throws JSONException {
|
||||||
JSONObject obj = new JSONObject();
|
JSONObject obj = new JSONObject();
|
||||||
obj.put("id", _id);
|
obj.put("id", _id);
|
||||||
obj.put("name", _name);
|
obj.put("name", _name);
|
||||||
|
|
30
app/src/main/java/me/impy/aegis/ext/AegisImporter.java
Normal file
30
app/src/main/java/me/impy/aegis/ext/AegisImporter.java
Normal file
|
@ -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…
Add table
Add a link
Reference in a new issue