def sign(text, options = {})
      options = @default_options.merge options

      plain  = Data.new(text)
      output = Data.new(options[:output])
      mode   = options[:mode] || GPGME::SIG_MODE_NORMAL

      GPGME::Ctx.new(options) do |ctx|
        if options[:signer]
          signers = Key.find(:secret, options[:signer], :sign)
          ctx.add_signer(*signers)
        end

        begin
          ctx.sign(plain, output, mode)
        rescue GPGME::Error::UnusableSecretKey => exc
          exc.keys = ctx.sign_result.invalid_signers
          raise exc
        end
      end

      output.seek(0)
      output
    end
def sign(text, options = {})
      options = @default_options.merge options

      plain  = Data.new(text)
      output = Data.new(options[:output])
      mode   = options[:mode] || GPGME::SIG_MODE_NORMAL

      GPGME::Ctx.new(options) do |ctx|
        if options[:signer]
          signers = Key.find(:secret, options[:signer], :sign)
          ctx.add_signer(*signers)
        end

        begin
          ctx.sign(plain, output, mode)
        rescue GPGME::Error::UnusableSecretKey => exc
          exc.keys = ctx.sign_result.invalid_signers
          raise exc
        end
      end

      output.seek(0)
      output
    end
Creates a signature of a text

   crypto.sign text, options

 Must have the appropiate key to be able to decrypt, of course. Returns
 a {GPGME::Data} object which can then be read.

 @param text
   The object that will be signed. Must be something that can be converted
   to {GPGME::Data}.

 @param [Hash] options
  Optional parameters.
   * +:signer+ sign identifier to sign the text with. Will use the first
    key it finds if none specified.
   * +:output+ if specified, it will write the output into it. It will be
     converted to a {GPGME::Data} object, so it could be a file for example.
   * +:mode+ Desired type of signature. Options are:
    - +GPGME::SIG_MODE_NORMAL+ for a normal signature. The default one if
      not specified.
    - +GPGME::SIG_MODE_DETACH+ for a detached signature
    - +GPGME::SIG_MODE_CLEAR+ for a cleartext signature
   * Any other option accepted by {GPGME::Ctx.new}

 @return [GPGME::Data] a {GPGME::Data} that can be read.

 @example normal sign
   crypto.sign "Hi there"

 @example outputing to a file
   file = File.open("text.sign", "w+")
   crypto.sign "Hi there", :options => file

 @example doing a detached signature
   crypto.sign "Hi there", :mode => GPGME::SIG_MODE_DETACH

 @example specifying the signer
   crypto.sign "Hi there", :signer => "mrsimo@example.com"

 @raise [GPGME::Error::UnusableSecretKey] TODO don't know when