Class: PKCS11::Slot

Inherits:
Object
  • Object
show all
Defined in:
lib/pkcs11/slot.rb

Overview

Each slot corresponds to a physical reader or other device interface. It may contain a token.

Instance Method Summary collapse

Instance Method Details

#C_CloseAllSessionsPKCS11::Slot Also known as: close_all_sessions

Closes all sessions an application has with a token.

Returns:



96
97
98
99
# File 'lib/pkcs11/slot.rb', line 96

def C_CloseAllSessions
  @pk.C_CloseAllSessions(@slot)
  self
end

#C_GetMechanismInfo(mechanism) ⇒ CK_MECHANISM_INFO Also known as: mechanism_info

Obtains information about a particular mechanism possibly supported by a token.

Parameters:

  • mechanism (Integer, Symbol)

Returns:



52
53
54
# File 'lib/pkcs11/slot.rb', line 52

def C_GetMechanismInfo(mechanism)
  @pk.C_GetMechanismInfo(@slot, string_to_handle('CKM_', mechanism))
end

#C_GetMechanismListArray<PKCS11::CKM_*> Also known as: mechanisms

C_GetMechanismList is used to obtain a list of mechanism types supported by a token.

Returns:

  • (Array<PKCS11::CKM_*>)


42
43
44
# File 'lib/pkcs11/slot.rb', line 42

def C_GetMechanismList
  @pk.C_GetMechanismList(@slot)
end

#C_GetSlotInfoPKCS11::CK_SLOT_INFO Also known as: info

Obtains information about a particular slot in the system.



28
29
30
# File 'lib/pkcs11/slot.rb', line 28

def C_GetSlotInfo
  @pk.C_GetSlotInfo(@slot)
end

#C_GetTokenInfoPKCS11::CK_TOKEN_INFO Also known as: token_info

Obtains information about a particular token in the system.



35
36
37
# File 'lib/pkcs11/slot.rb', line 35

def C_GetTokenInfo
  @pk.C_GetTokenInfo(@slot)
end

#C_InitToken(pin, label) ⇒ PKCS11::Slot Also known as: init_token

Initializes a token. The standard allows PIN values to contain any valid UTF8 character, but the token may impose subset restrictions.

Parameters:

  • pin (String)

    is the SO’s initial PIN

  • label (String)

    is the label of the token (max 32-byte).

Returns:



64
65
66
67
# File 'lib/pkcs11/slot.rb', line 64

def C_InitToken(pin, label)
  @pk.C_InitToken(@slot, pin, label.ljust(32, " "))
  self
end

#C_OpenSession(flags = CKF_SERIAL_SESSION) ⇒ PKCS11::Session Also known as: open

Opens a Session between an application and a token in a particular slot.

  • If called with block, yields the block with the session and closes the session when the is finished.

  • If called without block, returns the session object.

Parameters:

  • flags (Integer) (defaults to: CKF_SERIAL_SESSION)

    indicates the type of session. Default is read-only, use CKF_SERIAL_SESSION | CKF_RW_SESSION for read-write session.

Returns:



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/pkcs11/slot.rb', line 79

def C_OpenSession(flags=CKF_SERIAL_SESSION)
  nr = @pk.C_OpenSession(@slot, flags)
  sess = Session.new @pk, nr
  if block_given?
    begin
      yield sess
    ensure
      sess.close
    end
  else
    sess
  end
end

#to_intInteger Also known as: to_i

The slot handle.

Returns:

  • (Integer)


16
17
18
# File 'lib/pkcs11/slot.rb', line 16

def to_int
  @slot
end