コード例 #1
0
TInt CRefTestAgentData::Read(TDes8& aDes) 
	{
	return iServer.Read(aDes, aDes.MaxLength());
	}
コード例 #2
0
/**
    Read a portion of data from the device.
    Note: at present it _APPENDS_ data to the aDataDes, so the caller must take care of setting its length

    @param  aPos     media position in bytes
    @param  aLength  how many bytes to read
    @param  aDataDes data descriptor

    @return KErrNone on success, standard Epoc error code otherwise

*/
TInt CWinImgFileDevice::Read(TInt64 aPos,TInt aLength, TDes8& aDataDes)
{
    
    //__PRINT3(_L("#-- CWinImgFileDevice::Read, pos:%LU, len:%u, desMaxLen:%u"), aPos, aLength, aDataDes.MaxLength());

    ASSERT(HandleValid());
    ASSERT(aLength <= aDataDes.MaxLength());

    //-- check position on the volume
    const TInt64 maxPos = iDrvGeometry.TotalSizeInBytes();
    if(aPos < 0 || aPos > maxPos)
        return KErrArgument;

    const TInt64 lastPos = aPos+aLength;
    if(lastPos > maxPos)
        return KErrArgument;

    TUint32 dataLen = aLength;

    if(dataLen == 0)
        return KErrNone;

    DWORD dwRes;
    DWORD dwBytesRead = 0;

    //aDataDes.SetLength(0);

    try
    {
        //-- 1. position to the media 
        LONG  mediaPosHi = I64HIGH(aPos);
        const TUint32 mediaPosLo = I64LOW(aPos);

        dwRes = SetFilePointer(iDevHandle, mediaPosLo, &mediaPosHi, FILE_BEGIN);
        if(dwRes == INVALID_SET_FILE_POINTER)
            throw KDiskOpError;


        //-- 2. read data to the scratch buffer and copy it to the descriptor.
        ASSERT(ipScratchBuf);

        TUint32 rem = dataLen;
        
        while(rem)
        {
            const TUint32 bytesToRead = Min(KScratchBufSz, rem);
            if(!ReadFile(iDevHandle, ipScratchBuf, bytesToRead, &dwBytesRead, NULL))
                throw KDiskOpError;

            aDataDes.Append(ipScratchBuf, bytesToRead);
            rem-=bytesToRead;
        }

    }
    catch(TInt nErrId)
    {//-- some disk operation finished with the error
        (void)nErrId;
        ASSERT(nErrId == KDiskOpError);
        const DWORD dwWinErr = GetLastError();
        const TInt  epocErr = MapWinError(dwWinErr);
        
        __PRINT2(_L("#-- CWinImgFileDevice::Read() error! WinErr:%d, EpocErr:%d"), dwWinErr, epocErr);
        ASSERT(epocErr != KErrNone);

        return epocErr;
    }


    return KErrNone;
}
コード例 #3
0
// ---------------------------------------------------------------------------
// TOMASuplLocationData::GetLocationValue
// (other items were commented in a header).
// ---------------------------------------------------------------------------
//
EXPORT_C void TOMASuplLocationData::GetLocationValue(TDes8& aLocationValue) const
    {
    if(aLocationValue.MaxLength() >= iLocationValue.Length())
        aLocationValue.Copy(iLocationValue);
    }
コード例 #4
0
/** 
 Get the capabilities of the device. This function is not called by the 
 Symbian OS. However can be used by the LDD to get the capabilities from 
 the device/hardware. There is no definition for encoding capabilities, 
 and is a matter of convention between the LDD and the PDD.
 
 @param	aDes
 		descriptor returned after filling with capabilities 
 */ 
void DExDriverPhysicalDevice::GetCaps(TDes8& aDes) const
	{    
	// Package buffer of TCommCapsV03. This creates a descriptor
	// for the commcaps structure, and provide compatibility
	// to use with API using descriptors
	//
    TCommCaps3 capsBuf;
    
    // Retrieves the data structure from the package buffer
    //
	TCommCapsV03 &caps=capsBuf();
	
	// Baud rates supported by the UART device. However, channel may
	// be designed to support a subset of them as choice (applies to
	// other configurations as well).
	//
	caps.iRate=KCapsBps110|KCapsBps150|KCapsBps300|KCapsBps600\
		|KCapsBps1200|KCapsBps2400|KCapsBps4800|KCapsBps9600\
		|KCapsBps19200|KCapsBps38400|KCapsBps57600|KCapsBps115200;		
	
	// Databit size	
	caps.iDataBits=KCapsData5|KCapsData6|KCapsData7|KCapsData8;
	// Stop bits size supported
	caps.iStopBits=KCapsStop1|KCapsStop2;
	// Parity supported
	caps.iParity=KCapsParityNone|KCapsParityEven|KCapsParityOdd|KCapsParityMark|KCapsParitySpace;
	// Handshaking protocol supported by device
	caps.iHandshake=KCapsObeyXoffSupported|KCapsSendXoffSupported|
					KCapsObeyCTSSupported|KCapsFailCTSSupported|
					KCapsObeyDSRSupported|KCapsFailDSRSupported|
					KCapsObeyDCDSupported|KCapsFailDCDSupported|
					KCapsFreeRTSSupported|KCapsFreeDTRSupported;
	// Infrared mode
	caps.iSIR=1;
	// Signals supported
	caps.iSignals=KCapsSignalCTSSupported|KCapsSignalRTSSupported|KCapsSignalDTRSupported|
						KCapsSignalDSRSupported|KCapsSignalDCDSupported|KCapsSignalRNGSupported;
	// FIFO enable/disable					
	caps.iFifo=KCapsHasFifo;
	// Notifications supported
	caps.iNotificationCaps=KNotifyDataAvailableSupported|KNotifySignalsChangeSupported;
	caps.iRoleCaps=0;
	caps.iFlowControlCaps=0;
	// Break supported
	caps.iBreakSupported=ETrue;

	// [TDes8::MaxLength()] - Get the descriptor's length.
	TInt len = aDes.MaxLength();
	
	// [TDes8::FillZ(len)] -Fill the descriptor's data area with binary 
	// zeroes, replacing any existing data and change its length. 
	aDes.FillZ(len);
	
    TInt size = sizeof(caps);
    if (size>len)
    	size=len;
    
    // [TDes8::Copy()] - Copy the data of length (size) into aDes descriptor
    //  replacing any existing data in the descriptor.
    aDes.Copy((TUint8*)&caps, size);
        	
	aDes=capsBuf.Left(Min(capsBuf.Length(),aDes.MaxLength()));	
	}
コード例 #5
0
ファイル: BASE64.CPP プロジェクト: kuailexs/symbiandump-mw1
TInt CBase64CodecBase::Encode(const TDesC8& aSource, TDes8& aResult) const
//
// Encode an arbitrary number of octets in aSource append the output to aResult.
// If the number of octets in aSource is not a multiple of 3
// padding will be added terminating the encoding
//
{
    TInt sourceLength = aSource.Length();
    if (sourceLength == 0)
        return KErrNone;
    __ASSERT_ALWAYS(((sourceLength * 4)/3 + sourceLength%3) <= (aResult.MaxLength()-aResult.Length()), Panic(EBase64Overflow));

    sourceLength -= sourceLength%3;
    TUint8 sixBit=NULL;
    TText8 source;
    TInt i;

    for (i = 0; i < sourceLength; i++)
    {
        source=aSource[i];
        sixBit = STATIC_CAST(TUint8,(source & 0xFC) >> 2);
        aResult.Append(KBase64Alphabet[sixBit]);
        sixBit = NULL;
        sixBit = STATIC_CAST(TUint8,(source & 0x03) << 4);
        source=aSource[++i];
        sixBit |= STATIC_CAST(TUint8,(source & 0xF0) >> 4);
        aResult.Append(KBase64Alphabet[sixBit]);
        sixBit = NULL;
        sixBit = STATIC_CAST(TUint8,(source & 0x0F) << 2);
        source=aSource[++i];
        sixBit |= STATIC_CAST(TUint8,(source & 0xC0) >> 6);
        aResult.Append(KBase64Alphabet[sixBit]);
        sixBit = NULL;
        sixBit = STATIC_CAST(TUint8,(source & 0x3F));
        aResult.Append(KBase64Alphabet[sixBit]);
    }
    switch (aSource.Length() % 3)
    {
    case 2:
        source=aSource[i];
        sixBit = STATIC_CAST(TUint8,(source & 0xFC) >> 2);
        aResult.Append(KBase64Alphabet[sixBit]);
        sixBit = NULL;
        sixBit = STATIC_CAST(TUint8,(source & 0x03) << 4);
        source=aSource[++i];
        sixBit |= STATIC_CAST(TUint8,(source & 0xF0) >> 4);
        aResult.Append(KBase64Alphabet[sixBit]);
        sixBit = NULL;
        sixBit = STATIC_CAST(TUint8,(source & 0x0F) << 2);
        aResult.Append(KBase64Alphabet[sixBit]);
        aResult.Append(KBase64Alphabet[KBase64Pad]);
        break;
    case 1:
        source=aSource[i];
        sixBit = STATIC_CAST(TUint8,(source & 0xFC) >> 2);
        aResult.Append(KBase64Alphabet[sixBit]);
        sixBit = NULL;
        sixBit = STATIC_CAST(TUint8,(source & 0x03) << 4);
        aResult.Append(KBase64Alphabet[sixBit]);
        aResult.Append(KBase64Alphabet[KBase64Pad]);
        aResult.Append(KBase64Alphabet[KBase64Pad]);
        break;
    default:
        break;
    }
    return KErrNone;
}
コード例 #6
0
// -----------------------------------------------------------------------------
// CUpnpHttpChunkParser::ParseL
// Decoding the chunked-encoded buffer
// -----------------------------------------------------------------------------
//
TBool CUpnpHttpChunkParser::ParseHeader( TDes8& aBuffer, TInt& aPos )
	{
    if ( IsEmpty( aBuffer, aPos ) )
        {	    
        return ETrue;
        }
    iChunkSize = KErrNotFound;
    iBytesAppended = 0;
    TPtrC8 pointer(NULL,0);
    //if '\r\n' exists
    TInt lineFeed = aBuffer.Right( aBuffer.Length() - aPos ).FindF( UpnpString::KLineFeed );
    //if ';' exists
    TInt semiColon = aBuffer.Right( aBuffer.Length() - aPos ).FindF( UpnpString::KSemiColon );
    //semicolon ignored if occurs after the linefeed
    if ( semiColon !=KErrNotFound && lineFeed !=KErrNotFound && lineFeed<semiColon )
        {
        semiColon = KErrNotFound;
        }
    if ( semiColon !=KErrNotFound )
        {		
        pointer.Set(aBuffer.Right( aBuffer.Length() - aPos ).Mid( 0,semiColon ) );		
        }
    else if ( lineFeed !=KErrNotFound )
        {
        pointer.Set( aBuffer.Right( aBuffer.Length() - aPos ).Mid( 0,lineFeed ) );		
        }
    else
        {
        pointer.Set( aBuffer.Right( aBuffer.Length() - aPos ) );		
        }

    TLex8 lex( pointer );	
    //skip white spaces	
    lex.SkipSpace();
    TUint size;
    //neither semicolon nor linefeed found
    if ( lineFeed == KErrNotFound && semiColon == KErrNotFound )
        {
        //remember the num of cut spaces
        TInt len = lex.Offset();
        if ( !lex.Eos() )
            {
            //check the chunk header size for the limit
            TInt error = lex.Val( size, EHex );			
            if ( error!= KErrNone || size > KMaxTInt )	
                {
                //size too big
                iError = ( error ) ? error: EHttpInsufficientStorage;
                iContext = EError;
                return EFalse;
                }			
            }

        aBuffer.Delete( aPos,len );
        return ETrue;
        }
			
    //get size	
    TInt error = lex.Val( size, EHex );
    if ( error!= KErrNone || size > KMaxTInt )
        {
        //unexpected characters or size too big
        iError = ( error ) ? error: EHttpInsufficientStorage ;
        iContext = EError;
        return EFalse;
        }	
    iChunkSize = size;	
    //skip white spaces	
    lex.SkipSpace();	
    if ( !lex.Eos() )
        {
        //unexpected characters
        iError = KErrGeneral;
        iContext = EError;
        return EFalse;
        }
    if ( lineFeed != KErrNotFound )
        {
        //the whole chunk header is parsed
        aBuffer.Delete( aPos, lineFeed + UpnpString::KLineFeed().Length() );
        //chunk size == 0
        if ( !iChunkSize )
            {        
            iContext = ELastChunk;
            }
        else
            {        
            iContext = EBody;
            }
        return ( aPos == aBuffer.Length() );
        }
    else if ( semiColon != KErrNotFound )
        {
        //extension found, 
        //one character left - possible linefeed
        if ( aPos<aBuffer.Length() )
            {            
            aBuffer.Delete( aPos, aBuffer.Length() - aPos - 1 );		
            }
        iContext = EExtension;
        return ETrue;	
        }
        
    iError = KErrUnknown;	
    iContext = EError;	
    return EFalse;		    	
    }
コード例 #7
0
ファイル: padding.cpp プロジェクト: cdaffara/symbiandump-os2
void CPaddingNone::UnPadL(const TDesC8& aInput,TDes8& aOutput)
	{
	__ASSERT_DEBUG(aOutput.MaxLength() >= MaxPaddedLength(aInput.Length()), User::Panic(KCryptoPanic, ECryptoPanicOutputDescriptorOverflow));
	aOutput.Append(aInput);
	}
コード例 #8
0
 /**
  * Getter method to Get SIP URI
  */
 EXPORT_C void COMASuplThirdpartyId::GetSipUri(TDes8& aSIPUri)
     {
     if(iSipUri && aSIPUri.MaxLength() >= iSipUri->Length())
         aSIPUri.Copy(*iSipUri);
     }
コード例 #9
0
 /**
  * Getter method to Get IMS public id
  */
 EXPORT_C void COMASuplThirdpartyId::GetIMSPublicId(TDes8& aPublicId)
     {
     if(iIMSPublicId && aPublicId.MaxLength() >= iIMSPublicId->Length())
         aPublicId.Copy(*iIMSPublicId);
     }
コード例 #10
0
TInt TClientRequest::Write(TInt aParam, const TDesC8& aDes, TInt aOffset) const
	{
	TDes8* desPtr = (TDes8*)iParams[aParam];
	desPtr->Copy(aDes.Mid(aOffset));
	return KErrNone;
	}
コード例 #11
0
 /**
  * Getter method to Get MSISDN
  */
 EXPORT_C void COMASuplThirdpartyId::GetMSISDN(TDes8& aMSISDN)
     {
     if(aMSISDN.MaxLength() >= iMSISDN.Length())
         aMSISDN.Copy(iMSISDN);
     }
コード例 #12
0
void TClientRequest::Read(TInt aParam, TDes8& aDes, TInt aOffset) const
	{
	const TDesC8* desPtr = (const TDesC8*)iParams[aParam];
	aDes.Copy(desPtr->Mid(aOffset));
	}
コード例 #13
0
ファイル: mschap2.cpp プロジェクト: kuailexs/symbiandump-os2
inline void CPppMsChap2::GenerateAuthenticatorResponseL(
    const TDesC16& aPassword,
    const TDesC8& aNTResponse,
    const TDesC8& aPeerChallenge,
    const TDesC8& aAuthenticatorChallenge,
    const TDesC8& aUserName,
    TDes8& aAuthenticatorResponse)
/**
   Generates the expected MS-CHAP-V2 Authenticator Response Value.
   @param aPassword [in] The Microsoft Windows NT password (0 to 256
   Unicode char).
   @param aNTResponse [in] The MS-CHAP-V2 NT-Response (24 octets).
   @param aPeerChallenge [in] The Peer Challenge (16 octets).
   @param aAuthenticatorChallenge [in] The Authenticator Challenge (16
   octets).
   @param aUserName [in] The Microsoft Windows NT username (0 to 256
   char).
   @param aAuthenticatorResponse [out] The expected MS-CHAP-V2
   Authenticator Response Value encoded in the format
   "S=<auth_string>" as specified in RFC 2759 (42 octets).
   @note This function implements the GenerateAuthenticatorResponse
   routine specified in RFC 2759.
   @internalComponent
*/
{
    ASSERT(aPassword.Length()<=KPppMsChapMaxNTPasswordLength);
    ASSERT(aNTResponse.Length() == KPppMsChap2NTResponseSize);
    ASSERT(aPeerChallenge.Length() ==
           KPppMsChap2PeerChallengeSize);
    ASSERT(aAuthenticatorChallenge.Length() ==
           KPppMsChap2AuthenticatorChallengeSize);
    ASSERT(aUserName.Length()<=KPppMsChapMaxNTUserNameLength);
    ASSERT(aAuthenticatorResponse.Length() ==
           KPppMsChap2AuthenticatorResponseSize);

    HBufC8* passwordHashBuf=HBufC8::NewMaxLC(KPppMsChap2HashSize);
    TPtr8 passwordHash(passwordHashBuf->Des());

    NtPasswordHashL(aPassword, passwordHash);

    HashNtPasswordHashL(passwordHash, passwordHash);

    CSHA1* sha1 = CSHA1::NewL();
    CleanupStack::PushL(sha1);

// A magic string literal specified in RFC 2759 used in reponse
// generation by the GenerateAuthenticatorResponse routine for SHA-1
// encryption.
    _LIT8(KMagic1, "Magic server to client signing constant");


    sha1->Update(passwordHash);
    sha1->Update(aNTResponse);
    TPtrC8 hash(sha1->Final(KMagic1));


    HBufC8* challengeHashBuf =
        HBufC8::NewMaxLC(KPppMsChap2ChallengeHashSize);
    TPtr8 challengeHash(challengeHashBuf->Des());
    ChallengeHashL(aPeerChallenge,
                   aAuthenticatorChallenge,
                   aUserName,
                   challengeHash);

// Another magic string literal specified in RFC 2759 used in reponse
// generation by the GenerateAuthenticatorResponse routine for SHA-1
// encryption.
    _LIT8(KMagic2, "Pad to make it do more than one iteration");


    sha1->Update(hash);
    sha1->Update(challengeHash);
    const TUint8* pHash = sha1->Final(KMagic2).Ptr();


    _LIT8(KFormat,
          "S=%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X"
          "%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X");
    aAuthenticatorResponse.Format(KFormat,
                                  *pHash,
                                  *(pHash + 1),
                                  *(pHash + 2),
                                  *(pHash + 3),
                                  *(pHash + 4),
                                  *(pHash + 5),
                                  *(pHash + 6),
                                  *(pHash + 7),
                                  *(pHash + 8),
                                  *(pHash + 9),
                                  *(pHash + 10),
                                  *(pHash + 11),
                                  *(pHash + 12),
                                  *(pHash + 13),
                                  *(pHash + 14),
                                  *(pHash + 15),
                                  *(pHash + 16),
                                  *(pHash + 17),
                                  *(pHash + 18),
                                  *(pHash + 19));

    CleanupStack::PopAndDestroy(challengeHashBuf);

    CleanupStack::PopAndDestroy(sha1);
    CleanupStack::PopAndDestroy(passwordHashBuf);

    ASSERT(aAuthenticatorResponse.Length() ==
           KPppMsChap2AuthenticatorResponseSize);
}
コード例 #14
0
ファイル: mschap2.cpp プロジェクト: kuailexs/symbiandump-os2
inline void CPppMsChap2::ProcessFailureMessageL(
    const TDesC8& aFailureMessage,
    TUint& aErrorCode,
    TUint8& aRetryFlag,
    TDes8& aAuthChallenge,
    TUint8& aPasswordProtoVersion,
    TPtrC8& aMessage)
/**
   Processes a MS-CHAP-V2 Failure Message.
   @param aFailureMessage [in] A MS-CHAP-V2 Failure Message.  The
   Failure Message needs to be in the format specified in RFC 2759:
   "E=eeeeeeeeee R=r C=cccccccccccccccccccccccccccccccc V=vvvvvvvvvv
   M=<msg>".
   @param aErrorCode [out] The MS-CHAP-V2 Failure error code.
   @param aRetryFlag [out] The retry flag.  The flag will be set to
   "1" if a retry is allowed, and "0" if not.  When the authenticator
   sets this flag to "1" it disables short timeouts, expecting the
   peer to prompt the user for new credentials and resubmit the
   response.
   @param aAuthChallenge [out] The new Authenticator Challenge Value.
   @param aPasswordProtoVersion [out] The password changing protocol
   supported by the peer.
   @param aMessage [out] A failure text message.
   @internalComponent
*/
{
    ASSERT(aAuthChallenge.Length() ==
           KPppMsChap2AuthenticatorChallengeSize);

    TLex8 input(aFailureMessage);

    if (input.Get() != 'E')
        User::Leave(KErrGeneral);

    if (input.Get() != '=')
        User::Leave(KErrGeneral);


// RFC 2759: ""eeeeeeeeee" is the ASCII representation of a decimal
// error code (need not be 10 digits) corresponding to one of those
// listed below, though implementations should deal with codes not on
// this list gracefully."


    TInt ret;
    if ((ret = input.Val(aErrorCode))!=KErrNone)
        if (ret!= KErrOverflow)
            User::Leave(KErrGeneral);
        else
// Gracefully handle unusually large, yet valid, MS-CHAP-V2 specific
// error code values.  This code only handles the MS-CHAP-V2 specific
// error code values specified in RFC 2759.
            aErrorCode=0;

    input.SkipSpace();

    if (input.Get() != 'R')
        User::Leave(KErrGeneral);

    if (input.Get() != '=')
        User::Leave(KErrGeneral);

    if (input.Val(aRetryFlag, EDecimal)!=KErrNone)
        User::Leave(KErrGeneral);

    input.SkipSpace();

    if (input.Get() != 'C')
        User::Leave(KErrGeneral);

    if (input.Get() != '=')
        User::Leave(KErrGeneral);

    TPtrC8 token(input.NextToken());
// This field is 32 hexadecimal digits representing an ASCII
// representation of a new challenge value.  Each octet is represented
// in 2 hexadecimal digits.
    if (token.Length() != KPppMsChap2AuthenticatorChallengeSize*2)
        User::Leave(KErrGeneral);

    TLex8 lex;
    TUint8 octet;
    TUint8* pChallengeOctet =
        const_cast<TUint8*>(aAuthChallenge.Ptr());
    TUint8 i = 0;
    do
    {
        lex.Assign(token.Mid(i*2, 2));
        if (lex.Val(octet, EHex) != KErrNone)
            User::Leave(KErrGeneral);

        *(pChallengeOctet + i) = octet;
    }
    while (++i < KPppMsChap2AuthenticatorChallengeSize);

    input.SkipSpace();

    if (input.Get() != 'V')
        User::Leave(KErrGeneral);

    if (input.Get() != '=')
        User::Leave(KErrGeneral);


// RFC 2759: "The "vvvvvvvvvv" is the ASCII representation of a
// decimal version code (need not be 10 digits) indicating the
// password changing protocol version supported on the server.  For
// MS-CHAP-V2, this value SHOULD always be 3."


    if ((ret = input.Val(aPasswordProtoVersion, EDecimal)) !=
            KErrNone)
        if (ret != KErrOverflow)
            User::Leave(KErrGeneral);
        else
// Gracefully handle unusually large, yet valid, password changing
// protocol version values.  This code only handles the password
// changing protocol version values specified in RFC 2759.
            aPasswordProtoVersion=0;

    input.SkipSpace();

    switch (input.Get())
    {
    case 'M':
        if (input.Get() != '=')
            User::Leave(KErrGeneral);

        aMessage.Set(input.NextToken());
        break;

    case 0:
        break;

    default:
        User::Leave(KErrGeneral);
    }

    ASSERT(aAuthChallenge.Length() ==
           KPppMsChap2AuthenticatorChallengeSize);
}
コード例 #15
0
ファイル: MSCHAP.CPP プロジェクト: cdaffara/symbiandump-os2
inline void CPppMsChap::ProcessFailureMessageL(
					const TDesC8& aFailureMessage,
					TUint& aErrorCode, 
					TUint8& aRetryFlag, 
					TBool& aHasNewChallenge, 
					TDes8& aChallenge, 
					TUint8&	aPasswordProtoVersion)
/**
   Processes a MS-CHAP Failure Message.
   @param aFailureMessage [in] A MS-CHAP Failure Message.  The Failure
   Message needs to be in the format specified in RFC 2433:
   "E=eeeeeeeeee R=r C=cccccccccccccccc V=vvvvvvvvvv".
   @param aErrorCode [out] The MS-CHAP Failure error code.
   @param aRetryFlag [out] The retry flag.  The flag will be set to
   "1" if a retry is allowed, and "0" if not.  When the authenticator
   sets this flag to "1" it disables short timeouts, expecting the
   peer to prompt the user for new credentials and resubmit the
   response.
   @param aHasNewChallenge [out] The flag that indicates if the
   Failure Message contains a new Challenge Value.
   @param aChallenge [out] The new Challenge Value, if the Failure
   Message contains a one.
   @param aPasswordProtoVersion [out] The password changing protocol
   supported by the peer.
   @internalComponent
*/
	{
	ASSERT(aChallenge.Length() == KPppMsChapChallengeSize);
	
	TLex8 input(aFailureMessage);

	if (input.Get() != 'E')
		User::Leave(KErrGeneral);

	if (input.Get() != '=')
		User::Leave(KErrGeneral);


// RFC 2433: ""eeeeeeeeee" is the ASCII representation of a decimal
// error code (need not be 10 digits) corresponding to one of those
// listed below, though implementations should deal with codes not on
// this list gracefully."

	
	TInt ret;
	if ((ret = input.Val(aErrorCode)) != KErrNone)
		if (ret != KErrOverflow)
			User::Leave(KErrGeneral);
		else
// Gracefully handle unusually large, yet valid, MS-CHAP specific
// error code values.  This code only handles the MS-CHAP specific
// error code values specified in RFC 2433.
			aErrorCode=0;

	input.SkipSpace();

	if (input.Get() != 'R')
		User::Leave(KErrGeneral);

	if (input.Get() != '=')
		User::Leave(KErrGeneral);

	if (input.Val(aRetryFlag, EDecimal)!=KErrNone)
		User::Leave(KErrGeneral);

	input.SkipSpace();

	switch (input.Get())
		{
	case 'C':
		{		
		if (input.Get() != '=')
			User::Leave(KErrGeneral);

		TPtrC8 token(input.NextToken());
// This field is 16 hexadecimal digits representing an ASCII
// representation of a new challenge value.  Each octet is represented
// in 2 hexadecimal digits.
		if (token.Length() != KPppMsChapChallengeSize*2)
			User::Leave(KErrGeneral);

		TLex8 lex;
		TUint8 octet;
		TUint8* pChallengeOctet = 
			const_cast<TUint8*>(aChallenge.Ptr());
		TUint8 i = 0;
		do
			{
			lex.Assign(token.Mid(i*2, 2));
			if (lex.Val(octet, EHex) != KErrNone)
				User::Leave(KErrGeneral);

			*(pChallengeOctet + i) = octet;
			}
		while (++i < KPppMsChapChallengeSize);

		aHasNewChallenge = ETrue;

		input.SkipSpace();

		if (input.Get()!='V')
			{
			aPasswordProtoVersion = 1;
			User::Leave(KErrGeneral);
			}
		}

// As specified in RFC 2433, the field containing the ASCII
// representation of a new challenge value is optional, so fall
// through.
		

	case 'V':

// RFC 2433: "The "vvvvvvvvvv" is the decimal version code (need not
// be 10 digits) indicating the MS-CHAP protocol version supported on
// the server.  Currently, this is interesting only in selecting a
// Change Password packet type.  If the field is not present the
// version should be assumed to be 1; since use of the version 1
// Change Password packet has been deprecated, this field SHOULD
// always contain a value greater than or equal to 2."


		aHasNewChallenge = EFalse;

		if (input.Get() != '=')
			User::Leave(KErrGeneral);

		if ((ret=input.Val(aPasswordProtoVersion,
				EDecimal)) != KErrNone)
			if (ret!= KErrOverflow)
				User::Leave(KErrGeneral);
			else
// Gracefully handle unusually large, yet valid, password changing
// protocol version values.  This code only handles the password
// changing protocol version codes values specified in RFC 2433.
				aPasswordProtoVersion = 0;

		break;
	 
	default:
		aHasNewChallenge = EFalse;
		aPasswordProtoVersion = 1;
		}
	}
コード例 #16
0
 /**
  * Getter method to Get Mdn parameter
  */
 EXPORT_C void COMASuplThirdpartyId::GetMdnThirdPartyId(TDes8& aMdn)
     {
     if(aMdn.MaxLength() >= iMdn.Length())
         aMdn.Copy(iMdn);
     }
コード例 #17
0
ファイル: MSCHAP.CPP プロジェクト: cdaffara/symbiandump-os2
inline void CPppMsChap::ChallengeResponseL(const TDesC8& aChallenge,
					TDes8& aPaddablePasswordHash,
					TDes8& aResponse)
/**
   Computes the Challenge Response.
   @param aChallenge [in] A MS-CHAP Challenge (8 octets).
   @param aPaddablePasswordHash [in/out] The hash of the password in a
   paddable buffer (16 octets in a buffer with at least 21 octets
   maximum length).
   @param aResponse [out] The Challenge Response (24 octets).
   @note This function implements the ChallengeResponse routine
   specified in RFC 2433.
   @internalComponent
*/
	{
	ASSERT(aChallenge.Length()==KPppMsChapChallengeSize);
	ASSERT(aPaddablePasswordHash.Length()==KPppMsChapHashSize &&
		aPaddablePasswordHash.MaxLength() >=
			KPppMsChapPaddedHashSize);
	ASSERT(aResponse.Length() == KPppMsChapNTResponseSize);

// aPaddablePasswordHash contains the hash of the password (16 octets)
// zero-padded to 21 octets

// RFC 2433 - ChallengeResponse(): "Set ZPasswordHash to
// PasswordHash zero-padded to 21 octets", i.e. 5 octets
	aPaddablePasswordHash.AppendFill(0, 
					KPppMsChapPaddedHashSize -
						KPppMsChapHashSize);

// The first 8 octets of aResponse
	TPtr8 responseChunk(const_cast<TUint8*>(aResponse.Ptr()),
				KPppDESKeySize, 
				KPppDESKeySize);
	DesEncryptL(aChallenge,
		aPaddablePasswordHash.Left(KPppMsChapDESKeySize),
		responseChunk);

// The second 8 octets of aResponse
	responseChunk.Set(const_cast<TUint8*>(aResponse.Ptr()) +
					KPppDESKeySize, 
			KPppDESKeySize,
			KPppDESKeySize);
  	DesEncryptL(aChallenge,
		aPaddablePasswordHash.Mid(KPppMsChapDESKeySize,
			KPppMsChapDESKeySize), 
		responseChunk);

// The third 8 octets of aResponse
	responseChunk.Set(const_cast<TUint8*>(aResponse.Ptr()) +
		2*KPppDESKeySize, KPppDESKeySize, KPppDESKeySize);
 	DesEncryptL(aChallenge,
		aPaddablePasswordHash.Mid(2*KPppMsChapDESKeySize,
			KPppMsChapDESKeySize),
		responseChunk);


// Restore the original length of the password hash
	aPaddablePasswordHash.SetLength(KPppMsChapHashSize);

	ASSERT(aResponse.Length() == KPppMsChapNTResponseSize);
	}
コード例 #18
0
 /**
  * Getter method to Get URI
  */
 EXPORT_C void COMASuplThirdpartyId::GetURI(TDes8& aURI)
     {
     if(iURI && aURI.MaxLength() >= iURI->Length())
         aURI.Copy(*iURI);
     }
コード例 #19
0
// -----------------------------------------------------------------------------
// CUpnpHttpChunkParser::IsEmpty
// Decoding the chunked-encoded buffer
// -----------------------------------------------------------------------------
//
TBool CUpnpHttpChunkParser::IsEmpty( TDes8& aBuffer, TInt aPos )
    {
    return ( aPos >= aBuffer.Length() );
    }   
コード例 #20
0
TInt CTelephonyFunctions::GetLineStatus(const CTelephony::TPhoneLine& aLine, TDes8& aStatus)
/**
Get the current line status.
*/
	{
	TInt ret=KErrAccessDenied;
	
	if(IsFlightModeOn())
		{
		return KErrAccessDenied;
		}

	CTelephony::TCallStatusV1& CallStatusV1 = reinterpret_cast<CTelephony::TCallStatusV1&> ( const_cast<TUint8&> ( *aStatus.Ptr() ) );
	RMobileCall::TMobileCallStatus callStatus=RMobileCall::EStatusUnknown;

	switch(aLine)
	{
	case CTelephony::EVoiceLine:
		ret= iLineVoice.GetMobileLineStatus(callStatus);
		break;
	case CTelephony::EDataLine:
		if(iLineIsDataOpen)
			{
			ret= iLineData.GetMobileLineStatus(callStatus);
			}
		else
			{
			return KErrNotSupported;
			}
		break;
	case CTelephony::EFaxLine:
		if(iLineIsFaxOpen)
			{
			ret= iLineFax.GetMobileLineStatus(callStatus);
			}
		else
			{
			return KErrNotSupported;
			}
		break;
	default:
		return KErrNotFound;
	}
	GetCallStatus(callStatus, CallStatusV1.iStatus);
	return ret;
	}	
コード例 #21
0
ファイル: padding.cpp プロジェクト: cdaffara/symbiandump-os2
void CPaddingNone::DoPadL(const TDesC8& aInput,TDes8& aOutput)
	{
	aOutput.Append(aInput);
	}
コード例 #22
0
TInt CTelephonyFunctions::GetCallInfoL(TDes8& aCallSelect, TDes8& aCallInfo, TDes8& aRemoteInfo)
/**
Get the current call information.
*/
	{
    CTelephony::TCallSelectionV1& CallSelectionV1 = reinterpret_cast<CTelephony::TCallSelectionV1&> 
                                                        ( const_cast<TUint8&> ( *aCallSelect.Ptr() ) );
    
	if(CallSelectionV1.iLine != CTelephony::EVoiceLine)
		{
		return KErrAccessDenied;
		}

	if(IsFlightModeOn())
		{
		return KErrAccessDenied;
		}

    CTelephony::TCallInfoV1& CallInfoV1 = reinterpret_cast<CTelephony::TCallInfoV1&> 
                                                        ( const_cast<TUint8&> ( *aCallInfo.Ptr() ) );

    CTelephony::TRemotePartyInfoV1& RemotePartyInfoV1 = reinterpret_cast<CTelephony::TRemotePartyInfoV1&> 
                                                        ( const_cast<TUint8&> ( *aRemoteInfo.Ptr() ) );	

	TPtr8* callInfoPkgPtr;
	RMobileCall::TMobileCallInfoV1* callInfoObjPtr;

	if(iTsyVersion == KNoMultimodeTsy)
		{
		return KErrNotSupported;
		}
	else if(iTsyVersion==KETelExtMultimodeV1 || iTsyVersion==KETelExtMultimodeV2)
		{
		RMobileCall::TMobileCallInfoV1*  callInfoV1 = new(ELeave) RMobileCall::TMobileCallInfoV1; 
		CleanupStack::PushL(callInfoV1);
		RMobileCall::TMobileCallInfoV1Pckg* callInfoV1Pckg = new(ELeave) RMobileCall::TMobileCallInfoV1Pckg(*callInfoV1); 
		CleanupStack::PushL(callInfoV1Pckg);
		callInfoPkgPtr = callInfoV1Pckg;
		callInfoObjPtr = callInfoV1;
		}
	else	//TSY v3
		{
		RMobileCall::TMobileCallInfoV3*  callInfoV3 = new(ELeave) RMobileCall::TMobileCallInfoV3; 
		CleanupStack::PushL(callInfoV3);
		RMobileCall::TMobileCallInfoV3Pckg* callInfoV3Pckg = new(ELeave) RMobileCall::TMobileCallInfoV3Pckg(*callInfoV3); 
		CleanupStack::PushL(callInfoV3Pckg);
		callInfoPkgPtr = callInfoV3Pckg;
		callInfoObjPtr = callInfoV3;
		}
 
	TInt numOfCalls=0;
	User::LeaveIfError(iLineVoice.EnumerateCall(numOfCalls));
	if (numOfCalls==0)
		{
		User::Leave(KErrNotFound);
		}
	CArrayFixFlat<RMobileCall>* tempCallArray = new (ELeave) CArrayFixFlat<RMobileCall>(numOfCalls);
	CleanupStack::PushL(TCleanupItem(CloseArrayOfCallObjects, tempCallArray));
	TInt i;
	
	RLine::TCallInfo callinfo;
	RMobileCall::TMobileCallStatus callStatus;
	TBool callFound=EFalse;
	for(i=0; i<numOfCalls; i++)
   		{
   		User::LeaveIfError(iLineVoice.GetCallInfo(i,callinfo));
   		RMobileCall tempCall; 
 		
 		tempCallArray->AppendL(tempCall);
 		User::LeaveIfError(tempCallArray->At(i).OpenExistingCall(iLineVoice,callinfo.iCallName));
		User::LeaveIfError(tempCallArray->At(i).GetMobileCallStatus(callStatus));
		 				
		if((callStatus==RMobileCall::EStatusConnected) &&
			(CallSelectionV1.iSelect==CTelephony::EActiveCall))
			{
			User::LeaveIfError(tempCallArray->At(i).GetMobileCallInfo(*callInfoPkgPtr));
			callFound=ETrue;
			break;
			}
		else if((callStatus==RMobileCall::EStatusHold) &&
			(CallSelectionV1.iSelect==CTelephony::EHeldCall))
			{
			User::LeaveIfError(tempCallArray->At(i).GetMobileCallInfo(*callInfoPkgPtr));
			callFound=ETrue;
			break;
			}
		else if(((callStatus==RMobileCall::EStatusDialling) ||
			  	(callStatus==RMobileCall::EStatusRinging) ||
			 	(callStatus==RMobileCall::EStatusAnswering) ||
				(callStatus==RMobileCall::EStatusConnecting) ||
				(callStatus==RMobileCall::EStatusReconnectPending) ||
				(callStatus==RMobileCall::EStatusDisconnecting) ||
				(callStatus==RMobileCall::EStatusDisconnectingWithInband) ||
				(callStatus==RMobileCall::EStatusTransferring) ||
				(callStatus==RMobileCall:: EStatusTransferAlerting) 
				) &&
			(CallSelectionV1.iSelect==CTelephony::EInProgressCall))
			{
			User::LeaveIfError(tempCallArray->At(i).GetMobileCallInfo(*callInfoPkgPtr));
			callFound=ETrue;
			break;
			}
		
		}	
	
	CleanupStack::PopAndDestroy(tempCallArray);	//tempCallArray
	if(!callFound)
		{
		CleanupStack::PopAndDestroy(2); //(callInfoV1Pckg or callInfoV3Pckg) AND (callInfoV1 or callInfoV3)		
		return KErrNotFound;
		}
	
	GetCallStatus(callInfoObjPtr->iStatus, CallInfoV1.iStatus);	

	if (callInfoObjPtr->iValid & RMobileCall::KCallSecurity)
		{
		if(callInfoObjPtr->ExtensionId() == KETelExtMultimodeV3)
			{
			RMobileCall::TMobileCallInfoV3* callInfoV3Ptr = reinterpret_cast<RMobileCall::TMobileCallInfoV3*>(callInfoObjPtr);
			
			switch(callInfoV3Ptr->iSecurity)
				{
			case RMobilePhone::ECipheringGSM:
				CallInfoV1.iSecurity = CTelephony::ECipheringGSM;
				break;
			case RMobilePhone::ECipheringWCDMA:
				CallInfoV1.iSecurity = CTelephony::ECipheringWCDMA;
				break;
			case RMobilePhone::ECipheringOff:
			default:
				CallInfoV1.iSecurity = CTelephony::ECipheringOff;
				break;
				}		
			}
		else
			CallInfoV1.iSecurity = CTelephony::ECipheringOff;
		}
	else
		{
		CallInfoV1.iSecurity = CTelephony::TPhoneNetworkSecurity();
		}

	
	if (callInfoObjPtr->iValid & RMobileCall::KCallStartTime)
		{
		CallInfoV1.iStartTime = callInfoObjPtr->iStartTime;
		}
	else
		{
		CallInfoV1.iStartTime = TDateTime();
		}
	if (callInfoObjPtr->iValid & RMobileCall::KCallDuration)
		{
		CallInfoV1.iDuration = callInfoObjPtr->iDuration;
		}
	else
		{
		CallInfoV1.iDuration = 0;
		}
	if (callInfoObjPtr->iValid & RMobileCall::KCallExitCode)
		{
		CallInfoV1.iExitCode = callInfoObjPtr->iExitCode;
		}
	else
		{
		CallInfoV1.iExitCode = 0;
		}
	
	if (callInfoObjPtr->iValid & RMobileCall::KCallDialledParty)
		{
		CopyTelAddress(callInfoObjPtr->iDialledParty, CallInfoV1.iDialledParty);
		}
	else
		{
		CallInfoV1.iDialledParty = CTelephony::TTelAddress();
		}

	//see whether we have an existing handle on the call
	CallInfoV1.iCallId = -1;
	RMobileCall* poolCall=NULL;
	RMobileCall::TMobileCallInfoV1  poolCallInfoV1;
	RMobileCall::TMobileCallInfoV1Pckg poolCallInfoV1Pckg(poolCallInfoV1);
	TInt err;
	
	for(int k=0;k<CTelephony::EISVMaxNumOfCalls;k++)
		{
		//get RMobileCall object
		if((poolCall = Call((CTelephony::TCallId)k)) != NULL)
			{
			//get call name
			err = poolCall->GetMobileCallInfo(poolCallInfoV1Pckg);
			if(err ==KErrNone)
				{
				//compare call names
				if(poolCallInfoV1.iCallName.MatchF(callinfo.iCallName)==0)
					{
					CallInfoV1.iCallId = k;
					break;			
					}
				}			
			}		
		}
		
	//fill TRemotePartyInfoV1
	RMobileCall::TMobileCallRemotePartyInfoV1& mobileRemoteParty = callInfoObjPtr->iRemoteParty;
	
	switch(mobileRemoteParty.iRemoteIdStatus)
		{
	case RMobileCall::ERemoteIdentityAvailable:
		RemotePartyInfoV1.iRemoteIdStatus = CTelephony::ERemoteIdentityAvailable;
		break;
	case RMobileCall::ERemoteIdentitySuppressed:
		RemotePartyInfoV1.iRemoteIdStatus = CTelephony::ERemoteIdentitySuppressed;
		break;
	case RMobileCall::ERemoteIdentityUnknown:
	default:
		RemotePartyInfoV1.iRemoteIdStatus = CTelephony::ERemoteIdentityUnknown;		
		break;
		}
		
	RemotePartyInfoV1.iCallingName.Copy(mobileRemoteParty.iCallingName);
	CopyTelAddress(mobileRemoteParty.iRemoteNumber, RemotePartyInfoV1.iRemoteNumber);
		
	switch(mobileRemoteParty.iDirection)
		{
	case RMobileCall::EMobileOriginated:
		RemotePartyInfoV1.iDirection = CTelephony::EMobileOriginated;
		break;
	case RMobileCall::EMobileTerminated:
		RemotePartyInfoV1.iDirection = CTelephony::EMobileTerminated;
		break;
	case RMobileCall::EDirectionUnknown:
	default:
		RemotePartyInfoV1.iDirection = CTelephony::EDirectionUnknown;
		break;
		}	
	
	CleanupStack::PopAndDestroy(2); //(callInfoV1Pckg or callInfoV3Pckg) AND (callInfoV1 or callInfoV3)
	
	return KErrNone;
	}	
コード例 #23
0
ファイル: BASE64.CPP プロジェクト: kuailexs/symbiandump-mw1
TInt CBase64CodecBase::Decode(const TDesC8& aSource, TDes8& aResult)
//
// Decode the base64 stream in aSource append the output to aResult.
// Any non base64 chars are discarded while decoding
// Returns if either an end of stream is found, or all aSource is exhausted
//
// Octets are only decoded when complete
//
{
    __ASSERT_ALWAYS((aSource.Length() * 3)/4 <= (aResult.MaxLength() - aResult.Length()), Panic(EBase64Overflow));
    if (aSource.Length() == 0)
        return KErrNone;
    TText8* readPtr=CONST_CAST(TText8*,aSource.Ptr());
    TText8* writePtr=CONST_CAST(TText8*,aResult.Ptr());
    TText8* writeStart=writePtr;
    writePtr += aResult.Length();
    TText8 result;
    TText8* readEnd=(readPtr + aSource.Length());

    for (; readPtr < readEnd; readPtr++)
    {
        TUint8 base64code = Base64Char(*readPtr);
        switch (base64code)
        {
        case KBase64Pad:
            if (iQuartCount == 0)
                return KErrNone;
            result = STATIC_CAST(TText8,iQuart[0] << 2);
            result |= STATIC_CAST(TText8,((iQuart[1] & 0x30) >> 4));
            *writePtr=result;
            writePtr++;
            if (iQuartCount == 3)
            {
                result = STATIC_CAST(TText8,(iQuart[1] & 0x0F) << 4);
                result |= STATIC_CAST(TText8,((iQuart[2] & 0x3C) >> 2));
                *writePtr=result;
                writePtr++;
            }
            aResult.SetLength(writePtr-writeStart);
            iQuartCount = 0;
            return KErrNone;
        case KErrInvalidCharacter:
            // Do nothing
            break;
        default:
        {
            iQuart[iQuartCount++] = base64code;
            if (iQuartCount == 4)
            {
                result = STATIC_CAST(TText8,iQuart[0] << 2);
                result |= STATIC_CAST(TText8,((iQuart[1] & 0x30) >> 4));
                *writePtr=result;
                writePtr++;
                result = STATIC_CAST(TText8,(iQuart[1] & 0x0F) << 4);
                result |= STATIC_CAST(TText8,((iQuart[2] & 0x3C) >> 2));
                *writePtr=result;
                writePtr++;
                result = STATIC_CAST(TText8,((iQuart[2] & 0x03) << 6));
                result |= STATIC_CAST(TText8,iQuart[3]);
                *writePtr=result;
                writePtr++;
                iQuartCount = 0;
            }
        }
        }
コード例 #24
0
// -----------------------------------------------------------------------------
// CBTGPSNmeaBuffer::ReadSentences
// -----------------------------------------------------------------------------
TInt CBTGPSNmeaBuffer::ReadSentences(
            TDes8& aDest, 
            TInt& aBeginning) const
    {
    __ASSERT_DEBUG(aBeginning<iSize, Panic(EPanicIndexOutOfRange));
    
    //Clear destination descriptor
    aDest.Zero();

    TBool started = EFalse;
    TBool ended = EFalse;
    
    if(aBeginning==iBottom)
        {
        return KErrEof;
        }
    
    if(aBeginning == KBTGPSNmeaIndexNotSet)
        {
        if(iBuffer[iBottom]!=0)
            {
            //Buffer has been rotated
            aBeginning = iBottom;
            }
        else
            {
            //Read from 0 to iBottom
            aBeginning = 0;
            if(iBottom == 0)
                {
                return KErrEof;
                }
            }
        }
        
    do
        {
        TUint8 nextChar = iBuffer[aBeginning];
        if(nextChar == KNmeaSentenceLead)
            {
            //Mark start of NMEA sentences
            started = ETrue;
            }
            
        if(started && aDest.Length()<aDest.MaxLength())
            {
            aDest.Append(nextChar);
            }
            
        aBeginning ++;
        aBeginning = aBeginning%iSize;

        if(started && nextChar == KNmeaSentenceTerminator2)
            {
            //Mark end of the sentence.
            ended = ETrue;
            }
        }while(aBeginning!=iBottom && !ended);
    
    
    if(aDest.Length()!=0)
        {
        return KErrNone;
        }
        
    return KErrEof;
    }
コード例 #25
0
/**
    Read a portion of data from the device. 
    Note: at present it _APPENDS_ data to the aDataDes, so the caller must take care of setting its length

    @param  aPos     media position in bytes
    @param  aLength  how many bytes to read
    @param  aDataDes data descriptor

    @return KErrNone on success, standard Epoc error code otherwise

*/
TInt CWinVolumeDevice::Read(TInt64 aPos, TInt aLength, TDes8& aDataDes)
{
    //__PRINT2(_L("#-- CWinVolumeDevice::Read, pos:%LU, len:%u"), aPos, aLength);
 
    ASSERT(HandleValid());
    ASSERT(aLength <= aDataDes.MaxLength());

    //-- check position on the volume
    const TInt64 maxPos = iDrvGeometry.TotalSizeInBytes();
    if(aPos < 0 || aPos > maxPos)
        return KErrArgument;

    const TInt64 lastPos = aPos+aLength;

    if(lastPos > maxPos)
        return KErrArgument;
    //--


    TUint32 dataLen = aLength;

    if(dataLen == 0)
        return KErrNone;

    DWORD dwRes;
    DWORD dwBytesRead = 0;

    //aDataDes.SetLength(0);

    const TUint32 KSectorSize = BytesPerSector();
    
    try
    {
        LONG    mediaPosHi = I64HIGH(aPos);
        const TUint32 mediaPosLo = I64LOW(aPos);
        const TUint32 startPosOffset = mediaPosLo & (KSectorSize-1);
        
        //-- 1. position to the media with sector size granularity and read 1st sector
        dwRes = SetFilePointer(iDevHandle, mediaPosLo-startPosOffset, &mediaPosHi, FILE_BEGIN);
        if(dwRes == INVALID_SET_FILE_POINTER)
            throw KDiskOpError;

        //-- 1.1 read 1st sector
        if(!ReadFile(iDevHandle, ipScratchBuf, KSectorSize, &dwBytesRead, NULL))
            throw KDiskOpError;
        
        const TUint32 firstChunkLen = Min(dataLen, KSectorSize - startPosOffset);
        aDataDes.Append(ipScratchBuf+startPosOffset, firstChunkLen);
        dataLen-=firstChunkLen;

        if(dataLen == 0)
            return KErrNone; //-- no more data to read
    
        //-- 2. read whole number of sectors from the meida
        const TUint32 KBytesTail = dataLen & (KSectorSize-1); //-- number of bytes in the incomplete last sector
    
        ASSERT((KScratchBufSz % KSectorSize) == 0);

        TUint32 rem = dataLen - KBytesTail;
        while(rem)
        {
            const TUint32 bytesToRead = Min(KScratchBufSz, rem);
    
            if(!ReadFile(iDevHandle, ipScratchBuf, bytesToRead, &dwBytesRead, NULL))
                throw KDiskOpError;        
 
            aDataDes.Append(ipScratchBuf, bytesToRead);
            rem-=bytesToRead;
        }

        //-- 3. read the rest of the bytes in the incomplete last sector
        if(KBytesTail)
        {
            if(!ReadFile(iDevHandle, ipScratchBuf, KSectorSize, &dwBytesRead, NULL))
                throw KDiskOpError;    

            aDataDes.Append(ipScratchBuf, KBytesTail);
        }

    }//try
    catch(TInt nErrId)
    {//-- some disk operation finished with the error
        (void)nErrId;
        ASSERT(nErrId == KDiskOpError);
        const DWORD dwWinErr = GetLastError();
        const TInt  epocErr = MapWinError(dwWinErr);
        
        __PRINT2(_L("#-- CWinVolumeDevice::Read() error! WinErr:%d, EpocErr:%d"), dwWinErr, epocErr);
        ASSERT(epocErr != KErrNone);

        return epocErr;
    }

    return KErrNone;
}
コード例 #26
0
/**
Sets the MTP dataset buffer to be managed.
@param aBuffer The MTP dataset buffer to be managed.
*/
EXPORT_C void TMTPTypeFlatBase::SetBuffer(const TDes8& aBuffer)
    {
    iBuffer.Set(aBuffer.MidTPtr(0));
    iBuffer.SetLength(iBuffer.MaxLength());
    }
コード例 #27
0
ファイル: sl_cache.cpp プロジェクト: kuailexs/symbiandump-os1
/**
    Read data from the media through the directory cache.
    
    @param  aPos    linear media position to start reading with
    @param  aLength how many bytes to read
    @param  aDes    data will be placed there
*/
void CMediaWTCache::ReadL(TInt64 aPos,TInt aLength,TDes8& aDes)
    {
    
#ifdef _DEBUG
    if(iCacheDisabled)
        {//-- cache is disabled for debug purposes
        User::LeaveIfError(iDrive.ReadNonCritical(aPos, aLength, aDes));
        return;
        }
#endif //_DEBUG

    const TUint32 PageSz = PageSize();//-- cache page size

    //-- find out if aPos is in cache. If not, find a spare page and read data there
    TInt nPage = FindOrGrabReadPageL(aPos);
    CWTCachePage* pPage = iPages[nPage];

    const TUint32 bytesToPageEnd = (TUint32)(pPage->iStartPos+PageSz - aPos); //-- number of bytes from aPos to the end of the page

//    __PRINT5(_L("CMediaWTCache::ReadL: aPos=%lx, aLength=%x, page:%lx, pageSz:%x, bytesToPageEnd=%x"), aPos, aLength, pPage->iStartPos, PageSz, bytesToPageEnd);
    if((TUint32)aLength <= bytesToPageEnd) 
        {//-- the data section is in the cache page entirely, take data directly from the cache
        aDes.Copy(pPage->PtrInCachePage(aPos), aLength);
        }
    else
        {//-- Data to be read cross cache page boundary or probably we have more than 1 page to read

        TUint32 dataLen(aLength);   //-- current data length
        TInt64  currMediaPos(aPos); //-- current media position

        //-- 1. read data that are already in the current page
        aDes.Copy(pPage->PtrInCachePage(currMediaPos), bytesToPageEnd);

        dataLen -= bytesToPageEnd;
        currMediaPos += bytesToPageEnd;

        //-- 2. read whole pages of data
        while(dataLen >= PageSz)
            {
            nPage = FindOrGrabReadPageL(currMediaPos); //-- find out if currMediaPos is in cache. If not, find a spare page and read data there
            pPage = iPages[nPage];

            aDes.Append(pPage->PtrInCachePage(currMediaPos),PageSz);
        
            dataLen -= PageSz;
            currMediaPos += PageSz;
        
            MakePageLRU(nPage); //-- push the page to the top of the priority list
            }

        //-- 3. read the rest of the data
        if(dataLen >0)
            {
            nPage = FindOrGrabReadPageL(currMediaPos); //-- find out if currMediaPos is in cache. If not, find a spare page and read data there
            pPage = iPages[nPage];

            aDes.Append(pPage->PtrInCachePage(currMediaPos), dataLen);
            }

        } //else((TUint32)aLength <= bytesToPageEnd) 


    MakePageLRU(nPage); //-- push the page to the top of the priority list
    
    }
コード例 #28
0
void CIniFileParser::LogPathSetting(TDes8& aString) const
	{
	aString.Copy(iLoggingPathString);
	}
コード例 #29
0
// ---------------------------------------------------------------------------
// TOMASuplLocationData::SetLocationValue
// (other items were commented in a header).
// ---------------------------------------------------------------------------
//
EXPORT_C void TOMASuplLocationData::SetLocationValue(TDes8& aLocationValue) 
    {
    if(iLocationValue.MaxLength() >= aLocationValue.Length())
        iLocationValue.Copy( aLocationValue);
    }
コード例 #30
0
EXPORT_C TInt CIkeV2PkiService::Ikev2SignatureL(const TDesC8& aTrustedAuthority, 
                                                const TOwnCertInfo& aOwnCertInfo, 
                                                const TDesC8& aMsgOctets, 
                                                TDes8& aSignature, TUint8 aAuthMeth)
    {
    __ASSERT_ALWAYS(!IsActive(), User::Invariant());	

	TPKIKeyAlgorithm keyAlgorithm = EPKIRSA;	
    TInt length = aOwnCertInfo.iSubjectDnSuffix.Length();
    if ( length )
        {
        delete iSubjName;
        iSubjName = NULL;
        iSubjName = HBufC8::NewL(length);  	   			 
        iSubjName->Des().Copy(aOwnCertInfo.iSubjectDnSuffix);		
        }
    else 
        {
        iSubjName->Des().Zero();
        } 

    length = aOwnCertInfo.iRfc822NameFqdn.Length();
    if ( length )
        {
        delete iRfc822Name;
        iRfc822Name = NULL;
        iRfc822Name = HBufC8::NewL(length);  	   			 
        iRfc822Name->Des().Copy(aOwnCertInfo.iRfc822NameFqdn);        	 
        }
    else
        {
        iRfc822Name->Des().Zero();
        }

	//
	// Build PKCS1v15 format signature (ASN1 encoded) for RSA and SHA1 for DSA
	//
	CUtlMessageDigest* digest = TUtlCrypto::MakeMessageDigesterL(TUtlCrypto::EUtlMessageDigestSha1);
	CleanupStack::PushL(digest);
	HBufC8* asn1EncodedHash =NULL;
	HBufC8* DSSHash = NULL;
			
	switch( aAuthMeth )
		{
			case RSA_DIGITAL_SIGN:
				asn1EncodedHash = IkeCert::BuildPkcs1v15HashL(digest->Final(aMsgOctets));
				User::LeaveIfNull(asn1EncodedHash);
	    		CleanupStack::PopAndDestroy(digest);
    			CleanupStack::PushL(asn1EncodedHash);
    			User::LeaveIfError(iPkiService.Sign(aTrustedAuthority, *iSubjName, *iRfc822Name, 
		                                    		EX509DigitalSignature, aOwnCertInfo.iPrivateKeyLength, 
	                                    			keyAlgorithm, *asn1EncodedHash, aSignature));
   				CleanupStack::PopAndDestroy(asn1EncodedHash);
   				DEBUG_LOG(_L("Signing Auth data using RSA key."));
   				break;
			case DSS_DIGITAL_SIGN:
				DSSHash = HBufC8::New(20);
				DSSHash->Des().Append(digest->Final(aMsgOctets));
				CleanupStack::PopAndDestroy(digest);
    			CleanupStack::PushL(DSSHash);
				User::LeaveIfError(iPkiService.Sign(aTrustedAuthority, *iSubjName, *iRfc822Name, 
		                                    EX509DigitalSignature, aOwnCertInfo.iPrivateKeyLength, 
	                                    	keyAlgorithm, *DSSHash, aSignature));
   				CleanupStack::PopAndDestroy(DSSHash);
   				DEBUG_LOG(_L("Signing Auth data using DSA key."));
   				break;
   			default:
   				DEBUG_LOG1(_L("Authentication method %d not supported when using digital signatures."), aAuthMeth);
   				User::Leave(KErrNotSupported);
   				break;			
		}

	return aSignature.Length();
    }