public static int Generate(AuthSchemes scheme, int srand, int snum, ByteArrayPart targetname, SipMessageWriter writer, ref byte[] bytes)
                {
                    int length = 0;

                    Write(scheme.ToUtf8Bytes(), ref bytes, ref length);
                    WriteAsHex8(srand, ref bytes, ref length);
                    Write(snum, ref bytes, ref length);
                    Write(SipMicrosoftAuthentication.realm, ref bytes, ref length);

                    if (scheme == AuthSchemes.Kerberos)
                    {
                        Write(sip_, targetname, ref bytes, ref length);
                    }
                    else
                    {
                        Write(targetname, ref bytes, ref length);
                    }

                    Write(writer.CallId, ref bytes, ref length);
                    Write(writer.CSeq, ref bytes, ref length);
                    Write(writer.Method.ToByteArrayPart(), ref bytes, ref length);
                    Write(writer.FromAddrspec, ref bytes, ref length);
                    Write(writer.FromTag, ref bytes, ref length);
                    Write(writer.ToAddrspec, ref bytes, ref length);
                    Write(writer.ToTag, ref bytes, ref length);
                    // TODO: sip P-Asserted-Identity
                    WriteEmpty(ref bytes, ref length);
                    // TODO: tel P-Asserted-Identity
                    WriteEmpty(ref bytes, ref length);

                    if (writer.Expires != int.MinValue)
                    {
                        Write(writer.Expires, ref bytes, ref length);
                    }
                    else
                    {
                        WriteEmpty(ref bytes, ref length);
                    }

                    if (writer.IsResponse)
                    {
                        Write(writer.StatusCode, ref bytes, ref length);
                    }

                    //SIPServer.Tracer.Info("SignatureBuffer:" + Encoding.UTF8.GetString(bytes, 0, length));

                    return(length);
                }
                public static int Generate(AuthSchemes scheme, int srand, int snum, ByteArrayPart targetname, SipMessageReader reader, ref byte[] bytes)
                {
                    int length = 0;

                    Write(scheme.ToUtf8Bytes(), ref bytes, ref length);
                    WriteAsHex8(srand, ref bytes, ref length);
                    Write(snum, ref bytes, ref length);
                    Write(SipMicrosoftAuthentication.realm, ref bytes, ref length);

                    if (scheme == AuthSchemes.Kerberos)
                    {
                        Write(sip_, targetname, ref bytes, ref length);
                    }
                    else
                    {
                        Write(targetname, ref bytes, ref length);
                    }

                    Write(reader.CallId, ref bytes, ref length);
                    Write(reader.CSeq.Value, ref bytes, ref length);
                    Write(reader.Method.ToByteArrayPart(), ref bytes, ref length);
                    Write(reader.From.AddrSpec.Value, ref bytes, ref length);
                    Write(reader.From.Tag, ref bytes, ref length);
                    Write(reader.To.AddrSpec.Value, ref bytes, ref length);
                    Write(reader.To.Tag, ref bytes, ref length);
                    // TODO: sip P-Asserted-Identity
                    WriteEmpty(ref bytes, ref length);
                    // TODO: tel P-Asserted-Identity
                    WriteEmpty(ref bytes, ref length);

                    if (reader.Expires != int.MinValue)
                    {
                        Write(reader.Expires, ref bytes, ref length);
                    }
                    else
                    {
                        WriteEmpty(ref bytes, ref length);
                    }

                    if (reader.IsResponse)
                    {
                        Write(reader.StatusCode.Value, ref bytes, ref length);
                    }

                    return(length);
                }