mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-21 01:05:45 +00:00
Implementing BasicKeyedStreamGenerator.
This commit is contained in:
parent
6009219653
commit
f6dc75a755
@ -37,6 +37,7 @@ CPPSRCS = \
|
||||
nsWalletService.cpp \
|
||||
wallet.cpp \
|
||||
singsign.cpp \
|
||||
nsBasicStreamGenerator.cpp \
|
||||
$(NULL)
|
||||
|
||||
RES_FILES = \
|
||||
|
87
extensions/wallet/src/nsBasicStreamGenerator.cpp
Normal file
87
extensions/wallet/src/nsBasicStreamGenerator.cpp
Normal 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;
|
||||
}
|
55
extensions/wallet/src/nsBasicStreamGenerator.h
Normal file
55
extensions/wallet/src/nsBasicStreamGenerator.h
Normal 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;
|
||||
};
|
||||
|
@ -29,10 +29,20 @@
|
||||
// Define the constructor function for the 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
|
||||
static nsModuleComponentInfo components[] = {
|
||||
{ NS_WALLETSERVICE_CLASSNAME, NS_WALLETSERVICE_CID,
|
||||
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)
|
||||
|
Loading…
Reference in New Issue
Block a user