'Generate response-value.
Creates a response to a challenge according to section 2.1.2.1 of
RFC 2831 using the C{charset}, C{realm} and C{nonce} directives
from the challenge.'

def _genResponse(self, charset, realm, nonce):

    try:
        username = self.username.encode(charset)
        password = self.password.encode(charset)
        digest_uri = self.digest_uri.encode(charset)
    except UnicodeError:
        raise
    nc = networkString(('%08x' % (1,)))
    cnonce = self._gen_nonce()
    qop = 'auth'
    response = self._calculateResponse(cnonce, nc, nonce, username, password, realm, digest_uri)
    directives = {'username': username, 'realm': realm, 'nonce': nonce, 'cnonce': cnonce, 'nc': nc, 'qop': qop, 'digest-uri': digest_uri, 'response': response, 'charset': charset.encode('ascii')}
    return self._unparse(directives)
