<commit_before>crypto = require 'crypto'


exports.parseAuthHeader = (authHeader) ->
  res = {}
  i = authHeader.indexOf(' ')
  res['method'] = authHeader.slice(0, i)
  options = authHeader.slice(i + 1).split(/\s*,\s*/)
  
  for o in options
    v = o.split('=')
    res[v[0]] = v[1].slice(1, -1)
  return res


exports.basic = (username, password) ->
  "Basic #{new Buffer('Aladdin:open sesame').toString('base64')}"


exports.digest = (username, password, uri, httpMethod, body, authHeader) ->
  cnonce = '0a4f113b'
  nc = '00000001'

  if authHeader.qop?
    if authHeader.qop.indexOf(',') != -1
      qop = 'auth' # either auth or auth-int. prefer auth
    else
      qop = authHeader.qop

  ha1 = crypto.createHash('md5')
  ha1.update(username).update(':').update(authHeader.realm).update(':').update(password)
  # TODO support "MD5-sess" algorithm directive
  ha1 = ha1.digest('hex')

  ha2 = crypto.createHash('md5')
  ha2.update(httpMethod).update(':').update(uri)
  if qop == 'auth-int'
    ha2.update(':').update(body)
  ha2 = ha2.digest('hex')

  response = crypto.createHash('md5')
  response.update(ha1).update(':').update(authHeader.nonce)

  if authHeader.qop?
    response.update(':').update(nc).update(':').update(cnonce).update(':').update(authHeader.qop)
  response.update(':').update(ha2)
  response = response.digest('hex')
<commit_msg>Fixed wrong username/password in basic authentication<commit_after>crypto = require 'crypto'


exports.parseAuthHeader = (authHeader) ->
  res = {}
  i = authHeader.indexOf(' ')
  res['method'] = authHeader.slice(0, i)
  options = authHeader.slice(i + 1).split(/\s*,\s*/)
  
  for o in options
    v = o.split('=')
    res[v[0]] = v[1].slice(1, -1)
  return res


exports.basic = (username, password) ->
  "Basic #{new Buffer("#{username}:#{password}").toString('base64')}"


exports.digest = (username, password, uri, httpMethod, body, authHeader) ->
  cnonce = '0a4f113b'
  nc = '00000001'

  if authHeader.qop?
    if authHeader.qop.indexOf(',') != -1
      qop = 'auth' # either auth or auth-int. prefer auth
    else
      qop = authHeader.qop

  ha1 = crypto.createHash('md5')
  ha1.update(username).update(':').update(authHeader.realm).update(':').update(password)
  # TODO support "MD5-sess" algorithm directive
  ha1 = ha1.digest('hex')

  ha2 = crypto.createHash('md5')
  ha2.update(httpMethod).update(':').update(uri)
  if qop == 'auth-int'
    ha2.update(':').update(body)
  ha2 = ha2.digest('hex')

  response = crypto.createHash('md5')
  response.update(ha1).update(':').update(authHeader.nonce)

  if authHeader.qop?
    response.update(':').update(nc).update(':').update(cnonce).update(':').update(authHeader.qop)
  response.update(':').update(ha2)
  response = response.digest('hex')

{'fraction_non_alphanumeric': 0.19325598259608412, 'fraction_numerical': 0.026831036983321246, 'mean_word_length': 4.0346715328467155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6903911', 'n_tokens_mistral': 1037, 'n_tokens_neox': 989, 'n_words': 178}