Class UsagePeriod

java.lang.Object
net.messagevortex.asn1.AbstractBlock
net.messagevortex.asn1.UsagePeriod
All Implemented Interfaces:
Serializable, Comparable<UsagePeriod>, Block, Dumpable

public class UsagePeriod extends AbstractBlock implements Serializable, Comparable<UsagePeriod>
Represents a usage period.
See Also:
  • Field Details

    • serialVersionUID

      public static final long serialVersionUID
      See Also:
    • TAG_NOT_BEFORE

      public static final int TAG_NOT_BEFORE
      See Also:
    • TAG_NOT_AFTER

      public static final int TAG_NOT_AFTER
      See Also:
    • notBefore

      protected long notBefore
    • notAfter

      protected long notAfter
    • reference

      protected Date reference
    • type

      protected UsagePeriodType type
  • Constructor Details

    • UsagePeriod

      public UsagePeriod(long seconds)

      Creates a new object valid from this point in time for a duration of the specified amount of seconds.

      The validity time is created as relative time to the objects creation.

      Parameters:
      seconds - The number of seconds to be valid
    • UsagePeriod

      public UsagePeriod(long startSeconds, long durationSeconds)

      Creates a new object valid from this point plus startSeconds in time for a duration of the specified amount of seconds.

      The validity time is created as relative time to the objects creation.

      Parameters:
      startSeconds - the number of seconds after the current time the duration starts
      durationSeconds - the number of seconds of the duration
    • UsagePeriod

      public UsagePeriod(long startSeconds, long durationSeconds, Date reference)

      Constructor to create a relative usage period.

      Parameters:
      startSeconds - the number of seconds after the reference to start the period
      durationSeconds - the number of seconds the duration lasts
      reference - the date reference
    • UsagePeriod

      public UsagePeriod()

      Creates a new object valid from this point in time for the maximum possible duration.

    • UsagePeriod

      public UsagePeriod(UsagePeriod p)

      Copy constructor to copy a usage period.

      Parameters:
      p - the usage period to be copied
    • UsagePeriod

      public UsagePeriod(Date from, Date to)

      Creates a new object valid from this point in time for a duration of the specified amount of seconds.

      The validity time is created as absolute time.

      Parameters:
      from - the moment the object gains validity
      to - the moment the object validity ends
    • UsagePeriod

      public UsagePeriod(byte[] b) throws IOException

      Creates a new object by parsing the passed ASN.1 byte stream.

      Parameters:
      b - the stream to be parsed
      Throws:
      IOException - if parsing fails
    • UsagePeriod

      public UsagePeriod(org.bouncycastle.asn1.ASN1Encodable to) throws IOException

      Creates a new object by parsing the passed ASN.1 object.

      Parameters:
      to - the stream to be parsed
      Throws:
      IOException - if parsing fails
  • Method Details

    • parse

      protected final void parse(org.bouncycastle.asn1.ASN1Encodable to) throws IOException
      Specified by:
      parse in class AbstractBlock
      Throws:
      IOException
    • getNotBefore

      public Date getNotBefore()

      Gets the start of validity.

      Returns:
      the currently set start of the validity
    • setNotBefore

      public Date setNotBefore(Date validityStart)

      Sets the start date of validity.

      Parameters:
      validityStart - the new point in time to be set as start for the validity
      Returns:
      the previously set point in time
    • getNotAfter

      public Date getNotAfter()

      Gets the date of expiry.

      Returns:
      the currently set date of expiry
    • setNotAfter

      public Date setNotAfter(Date pointInTime)

      Sets the Date for expiriy of the validity.

      Parameters:
      pointInTime - the new date to be set
      Returns:
      the previously set date
    • getBeforeInt

      public long getBeforeInt()

      Gets the the absolute epoch of the start time.

      Returns:
      the absolute epoch in seconds
    • getAfterInt

      public long getAfterInt()

      Gets the the absolute epoch of the end time.

      Returns:
      the absolute epoch in seconds
    • toAsn1Object

      public org.bouncycastle.asn1.ASN1Object toAsn1Object(DumpType dumpType)
      Description copied from interface: Dumpable

      Dumps an ASN.1 representation of the object.

      Specified by:
      toAsn1Object in interface Dumpable
      Parameters:
      dumpType - the dump type to be used
      Returns:
      the ASN.1 string representation of the object
    • dumpValueNotation

      public String dumpValueNotation(String prefix, DumpType dumpType)

      Dumps the object as ASN.1 value notation.

      Specified by:
      dumpValueNotation in interface Block
      Parameters:
      prefix - the prefix to be prepended in front of each line
      Returns:
      the string representation of the object
    • inUsagePeriod

      public boolean inUsagePeriod()
    • inUsagePeriod

      public boolean inUsagePeriod(Date reference)

      checks whether the reference time is within the specified usage time.

      Parameters:
      reference - the time to to be taken into account when checking
      Returns:
      true if within bounds
    • compareTo

      public int compareTo(UsagePeriod other)
      Specified by:
      compareTo in interface Comparable<UsagePeriod>
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object