01: package net.suberic.pooka.crypto;
02:
03: import net.suberic.pooka.*;
04: import net.suberic.crypto.*;
05:
06: import javax.mail.internet.*;
07: import javax.mail.*;
08: import javax.activation.DataHandler;
09:
10: import java.security.Key;
11:
12: import java.io.*;
13:
14: /**
15: * A signed attachment.
16: */
17: public class KeyAttachment extends Attachment {
18:
19: boolean parsed = false;
20:
21: /**
22: * Creates a KeyAttachment out of a MimePart.
23: */
24: public KeyAttachment(MimePart mp) throws MessagingException {
25: super (mp);
26: }
27:
28: /**
29: * Returns the attached keys.
30: */
31: public Key[] extractKeys(EncryptionUtils utils)
32: throws MessagingException, java.io.IOException,
33: java.security.GeneralSecurityException {
34: net.suberic.crypto.UpdatableMBP mbp = new net.suberic.crypto.UpdatableMBP();
35:
36: mbp.setContent(getDataHandler().getContent(), getMimeType()
37: .toString());
38: mbp.updateMyHeaders();
39:
40: if (utils == null) {
41: utils = net.suberic.crypto.EncryptionManager
42: .getEncryptionUtils(mbp);
43: }
44:
45: if (utils != null)
46: return utils.extractKeys(mbp);
47: else
48: return null;
49: }
50:
51: }
|