Permalink
Browse files

refactor SignedMail to include Dkim::Options

  • Loading branch information...
1 parent 07393b1 commit 2c1eb9272f67b6c5d6f561702965bb0b1e7780ae @jhawthorn committed Apr 8, 2012
Showing with 7 additions and 42 deletions.
  1. +1 −1 lib/dkim/options.rb
  2. +6 −41 lib/dkim/signed_mail.rb
View
@@ -1,6 +1,6 @@
module Dkim
module Options
- ATTRIBUTES = :private_key, :signing_algorithm, :signable_headers, :domain, :selector, :time, :header_canonicalization, :body_canonicalization
+ ATTRIBUTES = :time, :private_key, :signing_algorithm, :signable_headers, :domain, :selector, :time, :header_canonicalization, :body_canonicalization
def options
@options ||= {}
end
View
@@ -4,55 +4,20 @@
require 'dkim/dkim_header'
require 'dkim/header'
require 'dkim/header_list'
+require 'dkim/options'
module Dkim
class SignedMail
+ include Options
+
def initialize message, options={}
message = message.to_s.gsub(/\r?\n/, "\r\n")
headers, body = message.split(/\r?\n\r?\n/, 2)
@headers = HeaderList.new headers
@body = Body.new body
- @signable_headers = options[:signable_headers]
- @domain = options[:domain]
- @selector = options[:selector]
- @time = options[:time]
- @signing_algorithm = options[:signing_algorithm]
- @private_key = options[:private_key]
- @header_canonicalization = options[:header_canonicalization]
- @body_canonicalization = options[:body_canonicalization]
- end
-
- # options for signatures
- attr_writer :signing_algorithm, :signable_headers, :domain, :selector, :time, :header_canonicalization, :body_canonicalization
-
- def private_key= key
- key = OpenSSL::PKey::RSA.new(key) if key.is_a?(String)
- @private_key = key
- end
- def private_key
- @private_key || Dkim::private_key
- end
- def signing_algorithm
- @signing_algorithm || Dkim::signing_algorithm
- end
- def signable_headers
- @signable_headers || Dkim::signable_headers
- end
- def domain
- @domain || Dkim::domain
- end
- def selector
- @selector || Dkim::selector
- end
- def time
- @time
- end
- def header_canonicalization
- @header_canonicalization || Dkim::header_canonicalization
- end
- def body_canonicalization
- @body_canonicalization || Dkim::body_canonicalization
+ # default options from Dkim.options
+ @options = Dkim.options.merge(options)
end
def signed_headers
@@ -113,7 +78,7 @@ def digest_alg
case signing_algorithm
when 'rsa-sha1'
OpenSSL::Digest::SHA1.new
- when 'rsa-sha256'
+ when 'rsa-sha256'
OpenSSL::Digest::SHA256.new
else
raise "Unknown digest algorithm: '#{signing_algorithm}'"

0 comments on commit 2c1eb92

Please sign in to comment.