correct the handling of unichar characters, r=dp

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

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

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

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

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