1 4 7 package javax.xml.crypto; 8 9 import java.security.Key ; 10 import javax.xml.crypto.dsig.keyinfo.KeyInfo; 11 import javax.xml.crypto.dsig.keyinfo.RetrievalMethod; 12 13 26 public abstract class KeySelector { 27 28 31 public static class Purpose { 32 33 private final String name; 34 35 private Purpose(String name) { this.name = name; } 36 37 43 public String toString() { return name; } 44 45 48 public static final Purpose SIGN = new Purpose("sign"); 49 52 public static final Purpose VERIFY = new Purpose("verify"); 53 56 public static final Purpose ENCRYPT = new Purpose("encrypt"); 57 60 public static final Purpose DECRYPT = new Purpose("decrypt"); 61 } 62 63 66 protected KeySelector() {} 67 68 94 public abstract KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, 95 AlgorithmMethod method, XMLCryptoContext context) 96 throws KeySelectorException; 97 98 106 public static KeySelector singletonKeySelector(Key key) { 107 return new SingletonKeySelector(key); 108 } 109 110 private static class SingletonKeySelector extends KeySelector { 111 private final Key key; 112 113 SingletonKeySelector(Key key) { 114 if (key == null) { 115 throw new NullPointerException (); 116 } 117 this.key = key; 118 } 119 120 public KeySelectorResult select(KeyInfo keyInfo, Purpose purpose, 121 AlgorithmMethod method, XMLCryptoContext context) 122 throws KeySelectorException { 123 124 return new KeySelectorResult() { 125 public Key getKey() { 126 return key; 127 } 128 }; 129 } 130 } 131 } 132 | Popular Tags |