JingleFile.java

 1package eu.siacs.conversations.xmpp.jingle;
 2
 3import java.io.File;
 4import java.security.Key;
 5
 6import javax.crypto.spec.SecretKeySpec;
 7
 8import eu.siacs.conversations.Config;
 9import eu.siacs.conversations.utils.CryptoHelper;
10import android.util.Log;
11
12public class JingleFile extends File {
13
14	private static final long serialVersionUID = 2247012619505115863L;
15
16	private long expectedSize = 0;
17	private String sha1sum;
18	private Key aeskey;
19
20	public JingleFile(String path) {
21		super(path);
22	}
23
24	public long getSize() {
25		return super.length();
26	}
27
28	public long getExpectedSize() {
29		if (this.aeskey != null) {
30			return (this.expectedSize / 16 + 1) * 16;
31		} else {
32			return this.expectedSize;
33		}
34	}
35
36	public void setExpectedSize(long size) {
37		this.expectedSize = size;
38	}
39
40	public String getSha1Sum() {
41		return this.sha1sum;
42	}
43
44	public void setSha1Sum(String sum) {
45		this.sha1sum = sum;
46	}
47
48	public void setKey(byte[] key) {
49		if (key.length >= 32) {
50			byte[] secretKey = new byte[32];
51			System.arraycopy(key, 0, secretKey, 0, 32);
52			this.aeskey = new SecretKeySpec(secretKey, "AES");
53		} else if (key.length >= 16) {
54			byte[] secretKey = new byte[16];
55			System.arraycopy(key, 0, secretKey, 0, 16);
56			this.aeskey = new SecretKeySpec(secretKey, "AES");
57		} else {
58			Log.d(Config.LOGTAG, "weird key");
59		}
60		Log.d(Config.LOGTAG,
61				"using aes key "
62						+ CryptoHelper.bytesToHex(this.aeskey.getEncoded()));
63	}
64
65	public Key getKey() {
66		return this.aeskey;
67	}
68}