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 byte[] 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 byte[] getSha1Sum() {
46 return this.sha1sum;
47 }
48
49 public void setSha1Sum(byte[] sum) {
50 this.sha1sum = sum;
51 }
52
53 public void setKeyAndIv(byte[] keyIvCombo) {
54 if (keyIvCombo.length == 48) {
55 this.aeskey = new byte[32];
56 this.iv = new byte[16];
57 System.arraycopy(keyIvCombo, 0, this.iv, 0, 16);
58 System.arraycopy(keyIvCombo, 16, this.aeskey, 0, 32);
59 } else if (keyIvCombo.length >= 32) {
60 this.aeskey = new byte[32];
61 System.arraycopy(keyIvCombo, 0, aeskey, 0, 32);
62 } else if (keyIvCombo.length >= 16) {
63 this.aeskey = new byte[16];
64 System.arraycopy(keyIvCombo, 0, this.aeskey, 0, 16);
65 }
66 }
67
68 public void setKey(byte[] key) {
69 this.aeskey = key;
70 }
71
72 public void setIv(byte[] iv) {
73 this.iv = iv;
74 }
75
76 public byte[] getKey() {
77 return this.aeskey;
78 }
79
80 public byte[] getIv() {
81 return this.iv;
82 }
83}