Class: Pdfrb::Encryption::SecurityHandler
- Inherits:
-
Object
- Object
- Pdfrb::Encryption::SecurityHandler
- Defined in:
- lib/pdfrb/encryption/security_handler.rb
Overview
Security handler base class. Subclasses implement decrypt,
encrypt, set_up_decryption, set_up_encryption. Dispatch
is via /Filter on the trailer's /Encrypt dict.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#encrypt_dict ⇒ Object
readonly
Returns the value of attribute encrypt_dict.
Class Method Summary collapse
-
.for(document, decryption_opts: {}) ⇒ Object
Dispatch on the trailer's /Encrypt /Filter.
- .register(filter_name, klass) ⇒ Object
- .registry ⇒ Object
Instance Method Summary collapse
- #decrypt(_bytes, _oid, _gen) ⇒ Object
- #encrypt(_bytes, _oid, _gen) ⇒ Object
- #encrypted? ⇒ Boolean
-
#initialize(document) ⇒ SecurityHandler
constructor
A new instance of SecurityHandler.
-
#set_up_decryption(**_opts) ⇒ Object
Subclasses override.
Constructor Details
#initialize(document) ⇒ SecurityHandler
Returns a new instance of SecurityHandler.
11 12 13 14 |
# File 'lib/pdfrb/encryption/security_handler.rb', line 11 def initialize(document) @document = document @encrypt_dict = nil end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
9 10 11 |
# File 'lib/pdfrb/encryption/security_handler.rb', line 9 def document @document end |
#encrypt_dict ⇒ Object (readonly)
Returns the value of attribute encrypt_dict.
9 10 11 |
# File 'lib/pdfrb/encryption/security_handler.rb', line 9 def encrypt_dict @encrypt_dict end |
Class Method Details
.for(document, decryption_opts: {}) ⇒ Object
Dispatch on the trailer's /Encrypt /Filter.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pdfrb/encryption/security_handler.rb', line 17 def self.for(document, decryption_opts: {}) trailer = document.trailer return nil unless trailer ref = trailer[:Encrypt] return nil unless ref encrypt = ref.is_a?(Pdfrb::Model::Reference) ? document.object(ref) : ref return nil unless encrypt filter = encrypt[:Filter] || :Standard klass = HANDLERS[filter.to_s] || raise(Pdfrb::EncryptionError, "unsupported /Filter #{filter.inspect}") handler = klass.new(document) handler.set_up_decryption(**decryption_opts) handler end |
.register(filter_name, klass) ⇒ Object
59 60 61 |
# File 'lib/pdfrb/encryption/security_handler.rb', line 59 def register(filter_name, klass) registry[filter_name.to_s] = klass end |
.registry ⇒ Object
57 |
# File 'lib/pdfrb/encryption/security_handler.rb', line 57 def registry; @registry ||= {}; end |
Instance Method Details
#decrypt(_bytes, _oid, _gen) ⇒ Object
41 42 43 |
# File 'lib/pdfrb/encryption/security_handler.rb', line 41 def decrypt(_bytes, _oid, _gen) raise NotImplementedError end |
#encrypt(_bytes, _oid, _gen) ⇒ Object
45 46 47 |
# File 'lib/pdfrb/encryption/security_handler.rb', line 45 def encrypt(_bytes, _oid, _gen) raise NotImplementedError end |
#encrypted? ⇒ Boolean
49 50 51 |
# File 'lib/pdfrb/encryption/security_handler.rb', line 49 def encrypted? !@encrypt_dict.nil? end |
#set_up_decryption(**_opts) ⇒ Object
Subclasses override.
37 38 39 |
# File 'lib/pdfrb/encryption/security_handler.rb', line 37 def set_up_decryption(**_opts) raise NotImplementedError end |