Implementing BasicKeyedStreamGenerator.

This commit is contained in:
dp%netscape.com 2000-02-01 07:03:57 +00:00
parent 6009219653
commit f6dc75a755
4 changed files with 153 additions and 0 deletions

View File

@ -37,6 +37,7 @@ CPPSRCS = \
nsWalletService.cpp \ nsWalletService.cpp \
wallet.cpp \ wallet.cpp \
singsign.cpp \ singsign.cpp \
nsBasicStreamGenerator.cpp \
$(NULL) $(NULL)
RES_FILES = \ RES_FILES = \

View File

@ -0,0 +1,87 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsBasicStreamGenerator.h"
const char * nsBasicStreamGenerator::mSignature = "Basic Keyed Stream Generator";
NS_IMPL_ISUPPORTS1(nsBasicStreamGenerator, nsIKeyedStreamGenerator)
nsBasicStreamGenerator::nsBasicStreamGenerator()
: mLevel(NS_SECURITY_LEVEL), mSalt(0), mPassword()
{
NS_INIT_ISUPPORTS();
}
nsBasicStreamGenerator::~nsBasicStreamGenerator()
{
}
NS_IMETHODIMP nsBasicStreamGenerator::GetSignature(char **signature)
{
NS_ENSURE_ARG_POINTER(signature);
*signature = nsCRT::strdup(mSignature);
return NS_OK;
}
NS_IMETHODIMP nsBasicStreamGenerator::Setup(PRUint32 salt, nsISupports *consumer)
{
// Forget everything about previous setup
mPasswordSink = nsnull;
// XXX whipe out the password to zero in memory
mPassword.Truncate(0);
// Reestablish setup
mSalt = salt;
if (consumer)
mPasswordSink = do_QueryInterface(consumer);
return NS_OK;
}
NS_IMETHODIMP nsBasicStreamGenerator::GetLevel(float *aLevel)
{
NS_ENSURE_ARG_POINTER(aLevel);
*aLevel = mLevel;
return NS_OK;
}
NS_IMETHODIMP nsBasicStreamGenerator::GetByte(PRUint32 offset, PRUint8 *retval)
{
NS_ENSURE_ARG_POINTER(retval);
nsresult rv = NS_OK;
if (!mPassword)
{
// First time we need the password. Get it.
if (!mPasswordSink) return NS_ERROR_FAILURE;
PRUnichar *aPassword;
rv = mPasswordSink->GetPassword(&aPassword);
if (NS_FAILED(rv)) return rv;
mPassword = aPassword;
nsAllocator::Free(aPassword);
}
// Get the offset byte from the stream. Our stream is
// just our password reapting itself infinite times.
*retval = mPassword[offset % mPassword.Length()];
return rv;
}

View File

@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsIKeyedStreamGenerator.h"
#include "nsIPasswordSink.h"
#include "nsString.h"
#include "nsCOMPtr.h"
#define NS_SECURITY_LEVEL 1.0
// {87496b68-1dd2-11b2-b080-ccabe9894783}
#define NS_BASIC_STREAM_GENERATOR_CID \
{ 0x87496b68, 0x1dd2, 0x11b2, { 0xb0, 0x80, 0xcc, 0xab, 0xe9, 0x89, 0x47, 0x83 } }
#define NS_BASIC_STREAM_GENERATOR_PROGID "component://netscape/keyed-stream-generator/basic"
#define NS_BASIC_STREAM_GENERATOR_CLASSNAME "Basic Keyed Stream Generator"
class nsBasicStreamGenerator : public nsIKeyedStreamGenerator
{
public:
NS_DECL_ISUPPORTS;
NS_DECL_NSIKEYEDSTREAMGENERATOR;
nsBasicStreamGenerator();
protected:
virtual ~nsBasicStreamGenerator();
private:
static const char *mSignature; // read only
float mLevel; // read only
PRUint32 mSalt; // not used for now
nsCString mPassword;
nsCOMPtr<nsIPasswordSink> mPasswordSink;
};

View File

@ -29,10 +29,20 @@
// Define the constructor function for the nsWalletlibService // Define the constructor function for the nsWalletlibService
NS_GENERIC_FACTORY_CONSTRUCTOR(nsWalletlibService) NS_GENERIC_FACTORY_CONSTRUCTOR(nsWalletlibService)
#if defined(XP_UNIX)
#include "nsBasicStreamGenerator.h"
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBasicStreamGenerator)
#endif
// The list of components we register // The list of components we register
static nsModuleComponentInfo components[] = { static nsModuleComponentInfo components[] = {
{ NS_WALLETSERVICE_CLASSNAME, NS_WALLETSERVICE_CID, { NS_WALLETSERVICE_CLASSNAME, NS_WALLETSERVICE_CID,
NS_WALLETSERVICE_PROGID, nsWalletlibServiceConstructor }, NS_WALLETSERVICE_PROGID, nsWalletlibServiceConstructor },
#if defined(XP_UNIX)
{ NS_BASIC_STREAM_GENERATOR_CLASSNAME, NS_BASIC_STREAM_GENERATOR_CID,
NS_BASIC_STREAM_GENERATOR_PROGID, nsBasicStreamGeneratorConstructor },
#endif
}; };
NS_IMPL_NSGETMODULE("nsWalletModule", components) NS_IMPL_NSGETMODULE("nsWalletModule", components)