other-licenses/7zstub/src/7zip/Archive/7z/7zMethodID.cpp

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

michael@0 1 // 7zMethodID.cpp
michael@0 2
michael@0 3 #include "StdAfx.h"
michael@0 4
michael@0 5 #include "7zMethodID.h"
michael@0 6
michael@0 7 namespace NArchive {
michael@0 8 namespace N7z {
michael@0 9
michael@0 10 static wchar_t GetHex(Byte value)
michael@0 11 {
michael@0 12 return (value < 10) ? ('0' + value) : ('A' + (value - 10));
michael@0 13 }
michael@0 14
michael@0 15 static bool HexCharToInt(wchar_t value, Byte &result)
michael@0 16 {
michael@0 17 if (value >= '0' && value <= '9')
michael@0 18 result = value - '0';
michael@0 19 else if (value >= 'a' && value <= 'f')
michael@0 20 result = 10 + value - 'a';
michael@0 21 else if (value >= 'A' && value <= 'F')
michael@0 22 result = 10 + value - 'A';
michael@0 23 else
michael@0 24 return false;
michael@0 25 return true;
michael@0 26 }
michael@0 27
michael@0 28 static bool TwoHexCharsToInt(wchar_t valueHigh, wchar_t valueLow, Byte &result)
michael@0 29 {
michael@0 30 Byte resultHigh, resultLow;
michael@0 31 if (!HexCharToInt(valueHigh, resultHigh))
michael@0 32 return false;
michael@0 33 if (!HexCharToInt(valueLow, resultLow))
michael@0 34 return false;
michael@0 35 result = (resultHigh << 4) + resultLow;
michael@0 36 return true;
michael@0 37 }
michael@0 38
michael@0 39 UString CMethodID::ConvertToString() const
michael@0 40 {
michael@0 41 UString result;
michael@0 42 for (int i = 0; i < IDSize; i++)
michael@0 43 {
michael@0 44 Byte b = ID[i];
michael@0 45 result += GetHex(b >> 4);
michael@0 46 result += GetHex(b & 0xF);
michael@0 47 }
michael@0 48 return result;
michael@0 49 }
michael@0 50
michael@0 51 bool CMethodID::ConvertFromString(const UString &srcString)
michael@0 52 {
michael@0 53 int length = srcString.Length();
michael@0 54 if ((length & 1) != 0 || (length >> 1) > kMethodIDSize)
michael@0 55 return false;
michael@0 56 IDSize = length / 2;
michael@0 57 UInt32 i;
michael@0 58 for(i = 0; i < IDSize; i++)
michael@0 59 if (!TwoHexCharsToInt(srcString[i * 2], srcString[i * 2 + 1], ID[i]))
michael@0 60 return false;
michael@0 61 for(; i < kMethodIDSize; i++)
michael@0 62 ID[i] = 0;
michael@0 63 return true;
michael@0 64 }
michael@0 65
michael@0 66 bool operator==(const CMethodID &a1, const CMethodID &a2)
michael@0 67 {
michael@0 68 if (a1.IDSize != a2.IDSize)
michael@0 69 return false;
michael@0 70 for (UInt32 i = 0; i < a1.IDSize; i++)
michael@0 71 if (a1.ID[i] != a2.ID[i])
michael@0 72 return false;
michael@0 73 return true;
michael@0 74 }
michael@0 75
michael@0 76 }}

mercurial