Class: HexaPDF::Encryption::StandardSecurityHandler

Inherits:
SecurityHandler show all
Defined in:
lib/hexapdf/encryption/standard_security_handler.rb

Overview

The password-based standard security handler of the PDF specification, identified by a /Filter value of /Standard.

Overview

The PDF specification defines one security handler that should be implemented by all PDF conform libraries and applications. This standard security handler allows access permissions and a user password as well as an owner password to be set. See StandardSecurityHandler::EncryptionOptions for all valid options that can be used with this security handler.

The access permissions (see StandardSecurityHandler::Permissions) can be used to restrict what a user is allowed to do with a PDF file.

When a user or owner password is specified, a PDF file can only be opened when the correct password is supplied.

See: PDF1.7 s7.6.3, PDF2.0 s7.6.3

Defined Under Namespace

Modules: Permissions Classes: EncryptionOptions

Instance Attribute Summary

Attributes inherited from SecurityHandler

#encryption_details

Instance Method Summary collapse

Methods inherited from SecurityHandler

#encrypt_string, #initialize, set_up_decryption, #set_up_decryption, set_up_encryption, #set_up_encryption

Constructor Details

This class inherits a constructor from HexaPDF::Encryption::SecurityHandler

Instance Method Details

#decrypt(obj) ⇒ Object

:nodoc:



243
244
245
246
247
248
249
# File 'lib/hexapdf/encryption/standard_security_handler.rb', line 243

def decrypt(obj) #:nodoc:
  if dict[:V] >= 4 && obj.type == :Metadata && obj[:Subtype] == :XML && !dict[:EncryptMetadata]
    obj
  else
    super
  end
end

#encrypt_stream(obj) ⇒ Object

:nodoc



251
252
253
254
255
256
257
# File 'lib/hexapdf/encryption/standard_security_handler.rb', line 251

def encrypt_stream(obj) #:nodoc
  if dict[:V] >= 4 && obj.type == :Metadata && obj[:Subtype] == :XML && !dict[:EncryptMetadata]
    obj.stream_encoder
  else
    super
  end
end

#encryption_key_valid?Boolean

Additionally checks that the document trailer's ID has not changed.

See: SecurityHandler#encryption_key_valid?

Returns:

  • (Boolean)


230
231
232
# File 'lib/hexapdf/encryption/standard_security_handler.rb', line 230

def encryption_key_valid?
  super && (document.trailer[:Encrypt][:R] > 4 || trailer_id_hash == @trailer_id_hash)
end

#permissionsObject

Returns the permissions of the managed dictionary as array of symbol values.

See: Permissions



237
238
239
240
241
# File 'lib/hexapdf/encryption/standard_security_handler.rb', line 237

def permissions
  Permissions::PERMISSION_TO_SYMBOL.each_with_object([]) do |(perm, sym), result|
    result << sym if dict[:P] & perm == perm
  end
end