class SSHKey

def build_ssh2_headers(headers = {})

def build_ssh2_headers(headers = {})
  return nil if headers.nil? || headers.empty?
  headers.keys.sort.collect do |header_tag|
    # header-tag must be us-ascii & <= 64 bytes and header-data must be UTF-8 & <= 1024 bytes
    raise PublicKeyError, "SSH2 header-tag '#{header_tag}' must be US-ASCII" unless header_tag.each_byte.all? {|b| b < 128 }
    raise PublicKeyError, "SSH2 header-tag '#{header_tag}' must be <= 64 bytes" unless header_tag.size <= 64
    raise PublicKeyError, "SSH2 header-value for '#{header_tag}' must be <= 1024 bytes" unless headers[header_tag].size <= 1024
    header_field = "#{header_tag}: #{headers[header_tag]}"
    header_field.scan(/.{1,#{SSH2_LINE_LENGTH}}/).join("\\\n")
  end.join("\n") << "\n"
end