Class Attribute

  • Direct Known Subclasses:
    AttributeArrayAttribute, BooleanAttribute, ByteArrayAttribute, CharArrayAttribute, DateAttribute, LongAttribute, MechanismArrayAttribute

    public abstract class Attribute
    extends java.lang.Object
    This is the base-class for all types of attributes. In general, all PKCS#11 objects are just a collection of attributes. PKCS#11 specifies which attributes each type of objects must have.

    In some cases, attributes are optional. In such a case, this attribute will return false when the application calls present() on this attribute. This means, that the object does not possess this attribute (maybe even though it should, but not all drivers seem to implement the standard correctly). Handling attributes in this fashion ensures that this library can work also with drivers that are not fully standard-compliant.

    Moreover, certain attributes can be sensitive; i.e. their values cannot be read, e.g. the private exponent of an RSA private key.

    Author:
    Karl Scheibelhofer (SIC), Lijun Liao (xipki)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected CK_ATTRIBUTE ckAttribute
      The CK_ATTRIBUTE that is used to hold the PKCS#11 type of this attribute and the value.
      protected boolean present
      True, if the object really possesses this attribute.
      protected boolean sensitive
      True, if this attribute is sensitive.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Attribute​(long type)
      Constructor taking the PKCS#11 type of the attribute.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      Attribute ckAttribute​(CK_ATTRIBUTE ckAttribute)
      Set the CK_ATTRIBUTE of this Attribute.
      CK_ATTRIBUTE getCkAttribute()
      Get the CK_ATTRIBUTE object of this Attribute that contains the attribute type and value .
      static Attribute getInstance​(long type)  
      static Attribute getInstance​(long type, java.lang.Object value)  
      long getType()
      Get the PKCS#11 type of this attribute.
      abstract java.lang.Object getValue()  
      protected java.lang.String getValueString()
      Get a string representation of the value of this attribute.
      boolean isNullValue()  
      boolean isPresent()
      Check, if this attribute is really present in the associated object.
      boolean isSensitive()
      Check, if this attribute is sensitive in the associated object.
      Attribute present​(boolean present)
      Set, if this attribute is really present in the associated object.
      Attribute sensitive​(boolean sensitive)
      Set, if this attribute is sensitive in the associated object.
      java.lang.String toString()
      Get a string representation of this attribute.
      java.lang.String toString​(boolean withName, int minNameLen, java.lang.String indent)
      Get a string representation of this attribute.
      long type()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • present

        protected boolean present
        True, if the object really possesses this attribute.
      • sensitive

        protected boolean sensitive
        True, if this attribute is sensitive.
      • ckAttribute

        protected CK_ATTRIBUTE ckAttribute
        The CK_ATTRIBUTE that is used to hold the PKCS#11 type of this attribute and the value.
    • Constructor Detail

      • Attribute

        protected Attribute​(long type)
        Constructor taking the PKCS#11 type of the attribute.
        Parameters:
        type - The PKCS#11 type of this attribute; e.g. CKA_PRIVATE.
    • Method Detail

      • getValue

        public abstract java.lang.Object getValue()
      • getInstance

        public static Attribute getInstance​(long type)
      • getInstance

        public static Attribute getInstance​(long type,
                                            java.lang.Object value)
      • present

        public Attribute present​(boolean present)
        Set, if this attribute is really present in the associated object. Does only make sense if used in combination with template objects.
        Parameters:
        present - True, if attribute is present.
        Returns:
        a reference to this object.
      • sensitive

        public Attribute sensitive​(boolean sensitive)
        Set, if this attribute is sensitive in the associated object. Does only make sense if used in combination with template objects.
        Parameters:
        sensitive - True, if attribute is sensitive.
        Returns:
        a reference to this object.
      • ckAttribute

        public Attribute ckAttribute​(CK_ATTRIBUTE ckAttribute)
        Set the CK_ATTRIBUTE of this Attribute. Only for internal use.
        Parameters:
        ckAttribute - The new CK_ATTRIBUTE of this Attribute.
        Returns:
        a reference to this object.
      • isPresent

        public boolean isPresent()
        Check, if this attribute is really present in the associated object.
        Returns:
        True, if this attribute is really present in the associated object.
      • isSensitive

        public boolean isSensitive()
        Check, if this attribute is sensitive in the associated object.
        Returns:
        True, if this attribute is sensitive in the associated object.
      • getCkAttribute

        public CK_ATTRIBUTE getCkAttribute()
        Get the CK_ATTRIBUTE object of this Attribute that contains the attribute type and value .
        Returns:
        The CK_ATTRIBUTE of this Attribute.
      • type

        public long type()
      • getValueString

        protected java.lang.String getValueString()
        Get a string representation of the value of this attribute.
        Returns:
        A string representation of the value of this attribute.
      • toString

        public java.lang.String toString()
        Get a string representation of this attribute. If the attribute is not present or if it is sensitive, the output of this method shows just a message telling this. This string does not contain the attribute's type name.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of the value of this attribute.
      • toString

        public java.lang.String toString​(boolean withName,
                                         int minNameLen,
                                         java.lang.String indent)
        Get a string representation of this attribute. If the attribute is not present or if it is sensitive, the output of this method shows just a message telling this.
        Parameters:
        withName - If true, the string contains the attribute type name and the value. If false, it just contains the value.
        minNameLen - Minimal length of the name.
        indent - The indent.
        Returns:
        A string representation of this attribute.
      • getType

        public long getType()
        Get the PKCS#11 type of this attribute.
        Returns:
        The PKCS#11 type of this attribute.
      • isNullValue

        public boolean isNullValue()