module DkimVerify::Verification
Constants
- HASHID_SHA1
- HASHID_SHA256
Public Class Methods
canonicalize_body(body, how)
click to toggle source
# File dkimverify.rb, line 315 def self.canonicalize_body(body, how) if how == "simple" $debuglog.puts "canonicalizing body with 'simple'" unless $debuglog.nil? # Ignore all empty lines at the end of the message body. body.gsub(/(\r\n)+\Z/, "\r\n") elsif how == "relaxed" $debuglog.puts "canonicalizing body with 'relaxed'" unless $debuglog.nil? body.gsub(/[\x09\x20]+\r\n/, "\r\n") # Remove all trailing WSP at end of lines. .gsub(/[\x09\x20]+/, " ") # Compress non-line-ending WSP to single space. .gsub(/(\r\n)+\Z/, "\r\n") # Ignore all empty lines at the end of the message body. # POTENTIAL PROBLEM: the python source has /(\r\n)*$/ so the + / * change is dubious end end
canonicalize_headers(headers, how)
click to toggle source
these two canonicalization methods are defined in the DKIM RFC
# File dkimverify.rb, line 301 def self.canonicalize_headers(headers, how) if how == "simple" # No changes to headers. $debuglog.puts "canonicalizing headers with 'simple'" unless $debuglog.nil? return headers elsif how == "relaxed" # Convert all header field names to lowercase. # Unfold all header lines. # Compress WSP to single space. # Remove all WSP at the start or end of the field value (strip). $debuglog.puts "canonicalizing headers with 'relaxed'" unless $debuglog.nil? headers.map{|k, v| [k.downcase, v.gsub(/\r\n/, '').gsub(/\s+/, " ").strip + "\r\n"] } end end
parse_header_kv(input_str)
click to toggle source
TODO: what is this kind of key-value string even called?
# File dkimverify.rb, line 99 def self.parse_header_kv(input_str) parsed = {} input_str.split(/\s*;\s*/m).each do |key_val| if m = key_val.match(/(\w+)\s*=\s*(.*)/m) parsed[m[1]] = m[2] end end parsed end