def enable_usage_rights(cert, pkey, *rights)

            # Always uses a detached PKCS7 signature for UR.
            method = Signature::PKCS7_DETACHED

            #
            # Load key pair
            #
            key = pkey.is_a?(OpenSSL::PKey::RSA) ? pkey : OpenSSL::PKey::RSA.new(pkey)
            certificate = cert.is_a?(OpenSSL::X509::Certificate) ? cert : OpenSSL::X509::Certificate.new(cert)

            #
            # Forge digital signature dictionary
            #
            digsig = Signature::DigitalSignature.new.set_indirect(true)

            self.Catalog.AcroForm ||= InteractiveForm.new
            #self.Catalog.AcroForm.SigFlags = InteractiveForm::SigFlags::APPEND_ONLY

            digsig.Type = :Sig
            digsig.Contents = HexaString.new("\x00" * Signature.required_size(method, certificate, key, []))
            digsig.Filter = :"Adobe.PPKLite"
            digsig.Name = "ARE Acrobat Product v8.0 P23 0002337"
            digsig.SubFilter = Name.new(method )
            digsig.ByteRange = [0, 0, 0, 0]

            sigref = Signature::Reference.new
            sigref.Type = :SigRef
            sigref.TransformMethod = :UR3
            sigref.Data = self.Catalog

            sigref.TransformParams = UsageRights::TransformParams.new
            sigref.TransformParams.P = true
            sigref.TransformParams.Type = :TransformParams
            sigref.TransformParams.V = UsageRights::TransformParams::VERSION

            rights.each do |right|
                sigref.TransformParams[right.first] ||= []
                sigref.TransformParams[right.first].concat(right[1..-1])
            end

            digsig.Reference = [ sigref ]

            self.Catalog.Perms ||= Perms.new
            self.Catalog.Perms.UR3 = digsig

            #
            #  Flattening the PDF to get file view.
            #
            compile

            #
            # Creating an empty Xref table to compute signature byte range.
            #
            rebuild_dummy_xrefs

            sig_offset = get_object_offset(digsig.no, digsig.generation) + digsig.signature_offset

            digsig.ByteRange[0] = 0
            digsig.ByteRange[1] = sig_offset
            digsig.ByteRange[2] = sig_offset + digsig.Contents.size

            until digsig.ByteRange[3] == filesize - digsig.ByteRange[2]
                digsig.ByteRange[3] = filesize - digsig.ByteRange[2]
            end

            # From that point on, the file size remains constant

            #
            # Correct Xrefs variations caused by ByteRange modifications.
            #
            rebuild_xrefs

            file_data = output()
            signable_data = file_data[digsig.ByteRange[0],digsig.ByteRange[1]] +
                file_data[digsig.ByteRange[2],digsig.ByteRange[3]]

            signature = Signature.compute(method, signable_data, certificate, key, [])
            digsig.Contents[0, signature.size] = signature

            #
            # No more modification are allowed after signing.
            #
            self.freeze
        end
def enable_usage_rights(cert, pkey, *rights)

            # Always uses a detached PKCS7 signature for UR.
            method = Signature::PKCS7_DETACHED

            #
            # Load key pair
            #
            key = pkey.is_a?(OpenSSL::PKey::RSA) ? pkey : OpenSSL::PKey::RSA.new(pkey)
            certificate = cert.is_a?(OpenSSL::X509::Certificate) ? cert : OpenSSL::X509::Certificate.new(cert)

            #
            # Forge digital signature dictionary
            #
            digsig = Signature::DigitalSignature.new.set_indirect(true)

            self.Catalog.AcroForm ||= InteractiveForm.new
            #self.Catalog.AcroForm.SigFlags = InteractiveForm::SigFlags::APPEND_ONLY

            digsig.Type = :Sig
            digsig.Contents = HexaString.new("\x00" * Signature.required_size(method, certificate, key, []))
            digsig.Filter = :"Adobe.PPKLite"
            digsig.Name = "ARE Acrobat Product v8.0 P23 0002337"
            digsig.SubFilter = Name.new(method )
            digsig.ByteRange = [0, 0, 0, 0]

            sigref = Signature::Reference.new
            sigref.Type = :SigRef
            sigref.TransformMethod = :UR3
            sigref.Data = self.Catalog

            sigref.TransformParams = UsageRights::TransformParams.new
            sigref.TransformParams.P = true
            sigref.TransformParams.Type = :TransformParams
            sigref.TransformParams.V = UsageRights::TransformParams::VERSION

            rights.each do |right|
                sigref.TransformParams[right.first] ||= []
                sigref.TransformParams[right.first].concat(right[1..-1])
            end

            digsig.Reference = [ sigref ]

            self.Catalog.Perms ||= Perms.new
            self.Catalog.Perms.UR3 = digsig

            #
            #  Flattening the PDF to get file view.
            #
            compile

            #
            # Creating an empty Xref table to compute signature byte range.
            #
            rebuild_dummy_xrefs

            sig_offset = get_object_offset(digsig.no, digsig.generation) + digsig.signature_offset

            digsig.ByteRange[0] = 0
            digsig.ByteRange[1] = sig_offset
            digsig.ByteRange[2] = sig_offset + digsig.Contents.size

            until digsig.ByteRange[3] == filesize - digsig.ByteRange[2]
                digsig.ByteRange[3] = filesize - digsig.ByteRange[2]
            end

            # From that point on, the file size remains constant

            #
            # Correct Xrefs variations caused by ByteRange modifications.
            #
            rebuild_xrefs

            file_data = output()
            signable_data = file_data[digsig.ByteRange[0],digsig.ByteRange[1]] +
                file_data[digsig.ByteRange[2],digsig.ByteRange[3]]

            signature = Signature.compute(method, signable_data, certificate, key, [])
            digsig.Contents[0, signature.size] = signature

            #
            # No more modification are allowed after signing.
            #
            self.freeze
        end
Enable the document Usage Rights.
 _rights_:: list of rights defined in UsageRights::Rights