1b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampackage org.bouncycastle.asn1; 2b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 3b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport java.io.IOException; 4c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstromimport java.text.ParseException; 5b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport java.text.SimpleDateFormat; 6b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport java.util.Date; 7b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallamimport java.util.SimpleTimeZone; 8b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 9b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam/** 10b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * UTC time object. 11b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 12b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallampublic class DERUTCTime 13c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom extends ASN1Object 14b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam{ 15b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String time; 16b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 17b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 18b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * return an UTC Time from the passed in object. 19b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 20b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @exception IllegalArgumentException if the object cannot be converted. 21b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 22b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static DERUTCTime getInstance( 23b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Object obj) 24b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 25b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (obj == null || obj instanceof DERUTCTime) 26b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 27b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return (DERUTCTime)obj; 28b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 29b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 30b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throw new IllegalArgumentException("illegal object in getInstance: " + obj.getClass().getName()); 31b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 32b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 33b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 34b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * return an UTC Time from a tagged object. 35b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 36b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param obj the tagged object holding the object we want 37b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param explicit true if the object is meant to be explicitly 38b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * tagged false otherwise. 39b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @exception IllegalArgumentException if the tagged object cannot 40b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * be converted. 41b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 42b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public static DERUTCTime getInstance( 43b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam ASN1TaggedObject obj, 44b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam boolean explicit) 45b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 466e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom DERObject o = obj.getObject(); 476e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom 486e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom if (explicit || o instanceof DERUTCTime) 496e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom { 506e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom return getInstance(o); 516e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom } 526e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom else 536e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom { 546e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom return new DERUTCTime(((ASN1OctetString)o).getOctets()); 556e736056d64d0e33b26cf9f7c4e351b496241fdeBrian Carlstrom } 56b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 57b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 58b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 59b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * The correct format for this is YYMMDDHHMMSSZ (it used to be that seconds were 60b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * never encoded. When you're creating one of these objects from scratch, that's 61b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * what you want to use, otherwise we'll try to deal with whatever gets read from 62b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * the input stream... (this is why the input format is different from the getTime() 63b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * method output). 64b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <p> 65b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * 66b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * @param time the time string. 67b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 68b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public DERUTCTime( 69b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String time) 70b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 71b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this.time = time; 72c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom try 73c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 74c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom this.getDate(); 75c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 76c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom catch (ParseException e) 77c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 78c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom throw new IllegalArgumentException("invalid date string: " + e.getMessage()); 79c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 80b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 81b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 82b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 83b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * base constructer from a java.util.date object 84b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 85b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public DERUTCTime( 86b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam Date time) 87b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 88b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam SimpleDateFormat dateF = new SimpleDateFormat("yyMMddHHmmss'Z'"); 89b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 90b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam dateF.setTimeZone(new SimpleTimeZone(0,"Z")); 91b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 92b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this.time = dateF.format(time); 93b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 94b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 95b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DERUTCTime( 96b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam byte[] bytes) 97b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 98b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam // 99b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam // explicitly convert to characters 100b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam // 101b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam char[] dateC = new char[bytes.length]; 102b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 103b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam for (int i = 0; i != dateC.length; i++) 104b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 105b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam dateC[i] = (char)(bytes[i] & 0xff); 106b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 107b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 108b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam this.time = new String(dateC); 109b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 110b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 111b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 112c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * return the time as a date based on whatever a 2 digit year will return. For 113c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * standardised processing use getAdjustedDate(). 114c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * 115c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @return the resulting date 116c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @exception ParseException if the date string cannot be parsed. 117c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 118c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public Date getDate() 119c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom throws ParseException 120c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 121c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom SimpleDateFormat dateF = new SimpleDateFormat("yyMMddHHmmssz"); 122c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 123c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return dateF.parse(getTime()); 124c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 125c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 126c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 127c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * return the time as an adjusted date 128c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * in the range of 1950 - 2049. 129c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * 130c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @return a date in the range of 1950 to 2049. 131c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * @exception ParseException if the date string cannot be parsed. 132c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom */ 133c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom public Date getAdjustedDate() 134c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom throws ParseException 135c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 136c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom SimpleDateFormat dateF = new SimpleDateFormat("yyyyMMddHHmmssz"); 137c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 138c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom dateF.setTimeZone(new SimpleTimeZone(0, "Z")); 139c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 140c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return dateF.parse(getAdjustedTime()); 141c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 142c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 143c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom /** 144b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * return the time - always in the form of 145b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * YYMMDDhhmmssGMT(+hh:mm|-hh:mm). 146b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <p> 147b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * Normally in a certificate we would expect "Z" rather than "GMT", 148b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * however adding the "GMT" means we can just use: 149b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <pre> 150b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * dateF = new SimpleDateFormat("yyMMddHHmmssz"); 151b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * </pre> 152b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * To read in the time and get a date which is compatible with our local 153b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * time zone. 154b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <p> 155b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * <b>Note:</b> In some cases, due to the local date processing, this 156b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * may lead to unexpected results. If you want to stick the normal 157b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * convention of 1950 to 2049 use the getAdjustedTime() method. 158b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 159b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public String getTime() 160b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 161b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam // 162b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam // standardise the format. 163b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam // 164c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (time.indexOf('-') < 0 && time.indexOf('+') < 0) 165b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 166c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (time.length() == 11) 167c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 168c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return time.substring(0, 10) + "00GMT+00:00"; 169c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 170c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom else 171c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 172c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return time.substring(0, 12) + "GMT+00:00"; 173c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 174b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 175c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom else 176b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 177c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom int index = time.indexOf('-'); 178c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (index < 0) 179c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 180c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom index = time.indexOf('+'); 181c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 182c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom String d = time; 183c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 184c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (index == time.length() - 3) 185c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 186c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom d += "00"; 187c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 188c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom 189c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (index == 10) 190c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 191c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return d.substring(0, 10) + "00GMT" + d.substring(10, 13) + ":" + d.substring(13, 15); 192c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 193c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom else 194c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom { 195c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom return d.substring(0, 12) + "GMT" + d.substring(12, 15) + ":" + d.substring(15, 17); 196c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom } 197b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 198b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 199b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 200b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam /** 201c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom * return a time string as an adjusted date with a 4 digit year. This goes 202b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam * in the range of 1950 - 2049. 203b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam */ 204b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public String getAdjustedTime() 205b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 206b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam String d = this.getTime(); 207b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 208b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam if (d.charAt(0) < '5') 209b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 210b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return "20" + d; 211b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 212b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam else 213b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 214b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return "19" + d; 215b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 216b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 217b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 218b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam private byte[] getOctets() 219b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 220b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam char[] cs = time.toCharArray(); 221b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam byte[] bs = new byte[cs.length]; 222b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 223b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam for (int i = 0; i != cs.length; i++) 224b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 225b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam bs[i] = (byte)cs[i]; 226b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 227b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 228b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return bs; 229b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 230b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 231b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam void encode( 232b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam DEROutputStream out) 233b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam throws IOException 234b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 235b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam out.writeEncoded(UTC_TIME, this.getOctets()); 236b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 237b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 238c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom boolean asn1Equals( 239c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom DERObject o) 240b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 241c37f4a04ef89e73a39a59f3c5a179af8c8ab5974Brian Carlstrom if (!(o instanceof DERUTCTime)) 242b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 243b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return false; 244b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 245b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 246b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return time.equals(((DERUTCTime)o).time); 247b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 248b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 249b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public int hashCode() 250b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 251b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return time.hashCode(); 252b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 253b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam 254b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam public String toString() 255b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam { 256b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam return time; 257b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam } 258b61a96e7ef1a78acf013bbf08fe537e5b5f129caPeter Hallam} 259