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		if (this.aeskey!=null) {
29			return (this.expectedSize/16 + 1) * 16;
30		} else {
31			return this.expectedSize;
32		}
33	}
34	
35	public void setExpectedSize(long size) {
36		this.expectedSize = size;
37	}
38	
39	public String getSha1Sum() {
40		return this.sha1sum;
41	}
42	
43	public void setSha1Sum(String sum) {
44		this.sha1sum = sum;
45	}
46	
47	public void setKey(byte[] key) {
48		if (key.length>=32) {
49			byte[] secretKey = new byte[32];
50			System.arraycopy(key, 0, secretKey, 0, 32);
51			this.aeskey = new SecretKeySpec(secretKey, "AES");
52		} else if (key.length>=16) {
53			byte[] secretKey = new byte[16];
54			System.arraycopy(key, 0, secretKey, 0, 16);
55			this.aeskey = new SecretKeySpec(secretKey, "AES");
56		} else {
57			Log.d("xmppService","weird key");
58		}
59		Log.d("xmppService","using aes key "+CryptoHelper.bytesToHex(this.aeskey.getEncoded()));
60	}
61	
62	public Key getKey() {
63		return this.aeskey;
64	}
65}