lib/hexapdf/encryption/standard_security_handler.rb in hexapdf-0.34.1 vs lib/hexapdf/encryption/standard_security_handler.rb in hexapdf-0.35.0
- old
+ new
@@ -248,10 +248,22 @@
Permissions::PERMISSION_TO_SYMBOL.each_with_object([]) do |(perm, sym), result|
result << sym if dict[:P] & perm == perm
end
end
+ # Returns the type of password used for decrypting the PDF document.
+ #
+ # The return value is one of the following:
+ #
+ # :none:: No password was needed for decryption.
+ # :user:: The provided user password was used for decryption.
+ # :owner:: The provided owner password was used for decryption.
+ # :unknown:: The document was not decrypted, only encrypted.
+ def decryption_password_type
+ @decryption_password_type || :unknown
+ end
+
def decrypt(obj) #:nodoc:
if dict[:V] >= 4 && obj.type == :Metadata && obj[:Subtype] == :XML && !dict[:EncryptMetadata]
obj
else
super
@@ -343,13 +355,16 @@
@trailer_id_hash = trailer_id_hash
password = prepare_password(password)
if user_password_valid?(prepare_password(''))
+ @decryption_password_type = :none
encryption_key = compute_user_encryption_key(prepare_password(''))
elsif user_password_valid?(password)
+ @decryption_password_type = :user
encryption_key = compute_user_encryption_key(password)
elsif owner_password_valid?(password)
+ @decryption_password_type = :owner
encryption_key = compute_owner_encryption_key(password)
else
raise HexaPDF::EncryptionError, "Invalid password specified"
end