1package eu.siacs.conversations.entities;
2
3import java.io.File;
4
5import eu.siacs.conversations.utils.MimeUtils;
6
7public class DownloadableFile extends File {
8
9 private static final long serialVersionUID = 2247012619505115863L;
10
11 private long expectedSize = 0;
12 private String sha1sum;
13 private byte[] aeskey;
14
15 private byte[] iv = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
16 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0xf };
17
18 public DownloadableFile(String path) {
19 super(path);
20 }
21
22 public long getSize() {
23 return super.length();
24 }
25
26 public long getExpectedSize() {
27 return this.expectedSize;
28 }
29
30 public String getMimeType() {
31 String path = this.getAbsolutePath();
32 int start = path.lastIndexOf('.') + 1;
33 if (start < path.length()) {
34 String mime = MimeUtils.guessMimeTypeFromExtension(path.substring(start));
35 return mime == null ? "" : mime;
36 } else {
37 return "";
38 }
39 }
40
41 public void setExpectedSize(long size) {
42 this.expectedSize = size;
43 }
44
45 public String getSha1Sum() {
46 return this.sha1sum;
47 }
48
49 public void setSha1Sum(String sum) {
50 this.sha1sum = sum;
51 }
52
53 public void setKeyAndIv(byte[] keyIvCombo) {
54 if (keyIvCombo.length == 48) {
55 byte[] secretKey = new byte[32];
56 byte[] iv = new byte[16];
57 System.arraycopy(keyIvCombo, 0, iv, 0, 16);
58 System.arraycopy(keyIvCombo, 16, secretKey, 0, 32);
59 this.aeskey = secretKey;
60 this.iv = iv;
61 } else if (keyIvCombo.length >= 32) {
62 byte[] secretKey = new byte[32];
63 System.arraycopy(keyIvCombo, 0, secretKey, 0, 32);
64 this.aeskey = secretKey;
65 } else if (keyIvCombo.length >= 16) {
66 byte[] secretKey = new byte[16];
67 System.arraycopy(keyIvCombo, 0, secretKey, 0, 16);
68 this.aeskey = secretKey;
69 }
70 }
71
72 public void setKey(byte[] key) {
73 this.aeskey = key;
74 }
75
76 public void setIv(byte[] iv) {
77 this.iv = iv;
78 }
79
80 public byte[] getKey() {
81 return this.aeskey;
82 }
83
84 public byte[] getIv() {
85 return this.iv;
86 }
87}