aboutsummaryrefslogtreecommitdiffstats
path: root/src/eu/siacs/conversations/xmpp/jingle/JingleFile.java
blob: 9253814b66fe86913fd2a7600d72de867427510c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package eu.siacs.conversations.xmpp.jingle;

import java.io.File;
import java.security.Key;

import javax.crypto.spec.SecretKeySpec;

import eu.siacs.conversations.Config;
import eu.siacs.conversations.utils.CryptoHelper;
import android.util.Log;

public class JingleFile extends File {

	private static final long serialVersionUID = 2247012619505115863L;

	private long expectedSize = 0;
	private String sha1sum;
	private Key aeskey;

	public JingleFile(String path) {
		super(path);
	}

	public long getSize() {
		return super.length();
	}

	public long getExpectedSize() {
		if (this.aeskey != null) {
			return (this.expectedSize / 16 + 1) * 16;
		} else {
			return this.expectedSize;
		}
	}

	public void setExpectedSize(long size) {
		this.expectedSize = size;
	}

	public String getSha1Sum() {
		return this.sha1sum;
	}

	public void setSha1Sum(String sum) {
		this.sha1sum = sum;
	}

	public void setKey(byte[] key) {
		if (key.length >= 32) {
			byte[] secretKey = new byte[32];
			System.arraycopy(key, 0, secretKey, 0, 32);
			this.aeskey = new SecretKeySpec(secretKey, "AES");
		} else if (key.length >= 16) {
			byte[] secretKey = new byte[16];
			System.arraycopy(key, 0, secretKey, 0, 16);
			this.aeskey = new SecretKeySpec(secretKey, "AES");
		} else {
			Log.d(Config.LOGTAG, "weird key");
		}
		Log.d(Config.LOGTAG,
				"using aes key "
						+ CryptoHelper.bytesToHex(this.aeskey.getEncoded()));
	}

	public Key getKey() {
		return this.aeskey;
	}
}