| 32 | import java.util.Vector; |
| 33 | |
| 34 | class LocalIdentityRepository implements IdentityRepository { |
| 35 | private static final String name = "Local Identity Repository"; |
| 36 | |
| 37 | private Vector identities = new Vector(); |
| 38 | private JSch jsch; |
| 39 | |
| 40 | LocalIdentityRepository(JSch jsch){ |
| 41 | this.jsch = jsch; |
| 42 | } |
| 43 | |
| 44 | public String getName(){ |
| 45 | return name; |
| 46 | } |
| 47 | |
| 48 | public int getStatus(){ |
| 49 | return RUNNING; |
| 50 | } |
| 51 | |
| 52 | public synchronized Vector getIdentities() { |
| 53 | removeDupulicates(); |
| 54 | Vector v = new Vector(); |
| 55 | for(int i=0; i<identities.size(); i++){ |
| 56 | v.addElement(identities.elementAt(i)); |
| 57 | } |
| 58 | return v; |
| 59 | } |
| 60 | |
| 61 | public synchronized void add(Identity identity) { |
| 62 | if(!identities.contains(identity)) { |
| 63 | byte[] blob1 = identity.getPublicKeyBlob(); |
| 64 | if(blob1 == null) { |
| 65 | identities.addElement(identity); |
| 66 | return; |
| 67 | } |
| 68 | for(int i = 0; i<identities.size(); i++){ |
| 69 | byte[] blob2 = ((Identity)identities.elementAt(i)).getPublicKeyBlob(); |
| 70 | if(blob2 != null && Util.array_equals(blob1, blob2)){ |
| 71 | if(!identity.isEncrypted() && |
| 72 | ((Identity)identities.elementAt(i)).isEncrypted()){ |
| 73 | remove(blob2); |
| 74 | } |
| 75 | else { |
| 76 | return; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | identities.addElement(identity); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | public synchronized boolean add(byte[] identity) { |
| 85 | try{ |
| 86 | Identity _identity = |
| 87 | IdentityFile.newInstance("from remote:", identity, null, jsch); |
| 88 | add(_identity); |
| 89 | return true; |
| 90 | } |
| 91 | catch(JSchException e){ |
nothing calls this directly
no outgoing calls
no test coverage detected