1 2 package com.ca.commons.security.cert.extensions; 3 4 import com.ca.commons.security.asn1.*; 5 6 23 public class KeyUsage implements V3Extension 24 { 25 String value = null; 26 27 public void init(ASN1Object asn1object) throws Exception 28 { 29 if (!asn1object.isASN1Type(ASN1Type.BIT_STRING)) 30 throw new Exception ("Wrong ASN.1 type for KeyUsage"); 31 32 byte[] o = (byte[]) asn1object.getValue(); 33 34 StringBuffer buff = new StringBuffer (); 35 36 if ((o[1] & (byte)0x80) != 0) 37 buff.append("digitalSignature, "); 38 if ((o[1] & (byte)0x40) != 0) 39 buff.append("nonRepudiation, "); 40 if ((o[1] & (byte)0x20) != 0) 41 buff.append("keyEncipherment, "); 42 if ((o[1] & (byte)0x10) != 0) 43 buff.append("dataEncipherment, "); 44 if ((o[1] & (byte)0x08) != 0) 45 buff.append("keyAgreement, "); 46 if ((o[1] & (byte)0x04) != 0) 47 buff.append("keyCertSign, "); 48 if ((o[1] & (byte)0x02) != 0) 49 buff.append("cRLSign, "); 50 if ((o[1] & (byte)0x01) != 0) 51 buff.append("encipherOnly, "); 52 if ((o[0] & (byte)0x80) != 0) buff.append("decipherOnly, "); 54 55 value = buff.toString(); 56 if (value.endsWith(", ")) 57 value = value.substring(0, value.length() - 2); 58 } 59 60 public String toString() 61 { 62 return value; 63 } 64 } 65 66 | Popular Tags |