diff options
author | iNPUTmice <daniel@gultsch.de> | 2014-08-31 16:28:21 +0200 |
---|---|---|
committer | iNPUTmice <daniel@gultsch.de> | 2014-08-31 16:28:21 +0200 |
commit | 1ac5be485502e7d6d4c117335e083c684739e6af (patch) | |
tree | 279c22e269158dde838f31ebcf3daf4272573583 /src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java | |
parent | 8d456085e57334dc34707a49666006619e2c77c6 (diff) |
some code cleanup
Diffstat (limited to '')
-rw-r--r-- | src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java b/src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java index 1acdfc39..07dc8ecc 100644 --- a/src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java +++ b/src/eu/siacs/conversations/xmpp/jingle/JingleTransport.java @@ -15,61 +15,72 @@ import javax.crypto.CipherInputStream; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; +import eu.siacs.conversations.Config; + import android.util.Log; public abstract class JingleTransport { public abstract void connect(final OnTransportConnected callback); - public abstract void receive(final JingleFile file, final OnFileTransmissionStatusChanged callback); - public abstract void send(final JingleFile file, final OnFileTransmissionStatusChanged callback); - private byte[] iv = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0xf}; - - protected InputStream getInputStream(JingleFile file) throws FileNotFoundException { + + public abstract void receive(final JingleFile file, + final OnFileTransmissionStatusChanged callback); + + public abstract void send(final JingleFile file, + final OnFileTransmissionStatusChanged callback); + + private byte[] iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, + 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0xf }; + + protected InputStream getInputStream(JingleFile file) + throws FileNotFoundException { if (file.getKey() == null) { return new FileInputStream(file); } else { try { IvParameterSpec ips = new IvParameterSpec(iv); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); - cipher.init(Cipher.ENCRYPT_MODE, file.getKey(),ips); - Log.d("xmppService","opening encrypted input stream"); + cipher.init(Cipher.ENCRYPT_MODE, file.getKey(), ips); + Log.d(Config.LOGTAG, "opening encrypted input stream"); return new CipherInputStream(new FileInputStream(file), cipher); } catch (NoSuchAlgorithmException e) { - Log.d("xmppService","no such algo: "+e.getMessage()); + Log.d(Config.LOGTAG, "no such algo: " + e.getMessage()); return null; } catch (NoSuchPaddingException e) { - Log.d("xmppService","no such padding: "+e.getMessage()); + Log.d(Config.LOGTAG, "no such padding: " + e.getMessage()); return null; } catch (InvalidKeyException e) { - Log.d("xmppService","invalid key: "+e.getMessage()); + Log.d(Config.LOGTAG, "invalid key: " + e.getMessage()); return null; } catch (InvalidAlgorithmParameterException e) { - Log.d("xmppService","invavid iv:"+e.getMessage()); + Log.d(Config.LOGTAG, "invavid iv:" + e.getMessage()); return null; } } } - - protected OutputStream getOutputStream(JingleFile file) throws FileNotFoundException { + + protected OutputStream getOutputStream(JingleFile file) + throws FileNotFoundException { if (file.getKey() == null) { return new FileOutputStream(file); } else { try { IvParameterSpec ips = new IvParameterSpec(iv); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); - cipher.init(Cipher.DECRYPT_MODE, file.getKey(),ips); - Log.d("xmppService","opening encrypted output stream"); - return new CipherOutputStream(new FileOutputStream(file), cipher); + cipher.init(Cipher.DECRYPT_MODE, file.getKey(), ips); + Log.d(Config.LOGTAG, "opening encrypted output stream"); + return new CipherOutputStream(new FileOutputStream(file), + cipher); } catch (NoSuchAlgorithmException e) { - Log.d("xmppService","no such algo: "+e.getMessage()); + Log.d(Config.LOGTAG, "no such algo: " + e.getMessage()); return null; } catch (NoSuchPaddingException e) { - Log.d("xmppService","no such padding: "+e.getMessage()); + Log.d(Config.LOGTAG, "no such padding: " + e.getMessage()); return null; } catch (InvalidKeyException e) { - Log.d("xmppService","invalid key: "+e.getMessage()); + Log.d(Config.LOGTAG, "invalid key: " + e.getMessage()); return null; } catch (InvalidAlgorithmParameterException e) { - Log.d("xmppService","invavid iv:"+e.getMessage()); + Log.d(Config.LOGTAG, "invavid iv:" + e.getMessage()); return null; } } |