correct the handling of unichar characters, r=dp

This commit is contained in:
morse%netscape.com 2000-02-12 02:04:25 +00:00
Родитель db4cd55837
Коммит c0732eea58
2 изменённых файлов: 12 добавлений и 6 удалений

Просмотреть файл

@ -27,7 +27,7 @@ const char * nsBasicStreamGenerator::mSignature = "Basic Keyed Stream Generator"
NS_IMPL_ISUPPORTS1(nsBasicStreamGenerator, nsIKeyedStreamGenerator)
nsBasicStreamGenerator::nsBasicStreamGenerator()
: mLevel(NS_SECURITY_LEVEL), mSalt(0), mPassword()
: mLevel(NS_SECURITY_LEVEL), mSalt(0), mPassword(), mState(0)
{
NS_INIT_ISUPPORTS();
}
@ -83,14 +83,19 @@ NS_IMETHODIMP nsBasicStreamGenerator::GetByte(PRUint32 offset, PRUint8 *retval)
if (NS_FAILED(rv)) return rv;
mPassword = aPassword;
nsAllocator::Free(aPassword);
mState = 0;
}
// Get the offset byte from the stream. Our stream is just our password
// repeating itself infinite times.
//
// mPassword being a nsCString, returns a PRUnichar for operator [].
// Hence convert it to a const char * first before applying op [].
*retval = ((const char *)mPassword)[offset % mPassword.Length()];
// mPassword being a nsString, its elements are PRUnichars.
// We want to return either the high-order or low-order 8 bits of the PRUnichar
// depending on whether or not this routine was called an odd or an even number of times
PRUnichar ret16 = mPassword.CharAt((mState>>1) % mPassword.Length());
if ((mState++) & 1) {
ret16 = ret16>>8;
}
*retval = (PRUint8)(ret16 & 0xff);
return rv;
}

Просмотреть файл

@ -50,7 +50,8 @@ class nsBasicStreamGenerator : public nsIKeyedStreamGenerator
static const char *mSignature; // read only
float mLevel; // read only
PRUint32 mSalt; // not used for now
nsCString mPassword;
nsString mPassword;
nsCOMPtr<nsIWeakReference> mWeakPasswordSink; // nsIPasswordSink
PRInt32 mState;
};