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.utils.CryptoHelper;
 9import android.util.Log;
10
11public class JingleFile extends File {
12	
13	private static final long serialVersionUID = 2247012619505115863L;
14	
15	private long expectedSize = 0;
16	private String sha1sum;
17	private Key aeskey;
18	
19	public JingleFile(String path) {
20		super(path);
21	}
22	
23	public long getSize() {
24		return super.length();
25	}
26	
27	public long getExpectedSize() {
28		return this.expectedSize;
29	}
30	
31	public void setExpectedSize(long size) {
32		this.expectedSize = size;
33	}
34	
35	public String getSha1Sum() {
36		return this.sha1sum;
37	}
38	
39	public void setSha1Sum(String sum) {
40		this.sha1sum = sum;
41	}
42	
43	public void setKey(byte[] key) {
44		Log.d("xmppService","using aes key "+CryptoHelper.bytesToHex(key));
45		if (key.length>=32) {
46			byte[] secretKey = new byte[32];
47			System.arraycopy(key, 0, secretKey, 0, 32);
48			this.aeskey = new SecretKeySpec(key, "AES");
49		} else if (key.length>=16) {
50			byte[] secretKey = new byte[15];
51			System.arraycopy(key, 0, secretKey, 0, 16);
52			this.aeskey = new SecretKeySpec(key, "AES");
53		} else {
54			Log.d("xmppService","weird key");
55		}
56	}
57	
58	public Key getKey() {
59		return this.aeskey;
60	}
61}