mirror of
https://github.com/bitwarden/mobile.git
synced 2024-11-14 10:15:56 +01:00
load EEFLongWordList from file
This commit is contained in:
parent
0bbb549533
commit
25d02cec25
@ -117,9 +117,9 @@ namespace Bit.App
|
||||
System.Diagnostics.Debug.WriteLine("XF App: OnStart");
|
||||
await ClearCacheIfNeededAsync();
|
||||
// Prime the word list
|
||||
var workTask = Task.Run(() =>
|
||||
var wordTask = Task.Run(() =>
|
||||
{
|
||||
var word = WordList.EEFLongWordList[1];
|
||||
// var word = WordList.EEFLongWordList[1];
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -13,10 +13,12 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Resources\eff_long_word_list.txt" />
|
||||
<None Remove="Resources\public_suffix_list.dat" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources\eff_long_word_list.txt" />
|
||||
<EmbeddedResource Include="Resources\public_suffix_list.dat" />
|
||||
</ItemGroup>
|
||||
|
||||
|
7776
src/Core/Resources/eff_long_word_list.txt
Normal file
7776
src/Core/Resources/eff_long_word_list.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -8,6 +8,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Numerics;
|
||||
using Bit.Core.Utilities;
|
||||
|
||||
namespace Bit.Core.Services
|
||||
{
|
||||
@ -793,7 +794,7 @@ namespace Bit.Core.Services
|
||||
|
||||
private List<string> HashPhrase(byte[] hash, int minimumEntropy = 64)
|
||||
{
|
||||
var wordLength = Utilities.WordList.EEFLongWordList.Count;
|
||||
var wordLength = EEFLongWordList.Instance.List.Count;
|
||||
var entropyPerWord = Math.Log(wordLength) / Math.Log(2);
|
||||
var numWords = (int)Math.Ceiling(minimumEntropy / entropyPerWord);
|
||||
|
||||
@ -810,7 +811,7 @@ namespace Bit.Core.Services
|
||||
{
|
||||
var remainder = (int)(hashNumber % wordLength);
|
||||
hashNumber = hashNumber / wordLength;
|
||||
phrase.Add(Utilities.WordList.EEFLongWordList[remainder]);
|
||||
phrase.Add(EEFLongWordList.Instance.List[remainder]);
|
||||
}
|
||||
return phrase;
|
||||
}
|
||||
|
@ -191,12 +191,12 @@ namespace Bit.Core.Services
|
||||
{
|
||||
options.WordSeparator = " ";
|
||||
}
|
||||
var listLength = WordList.EEFLongWordList.Count - 1;
|
||||
var listLength = EEFLongWordList.Instance.List.Count - 1;
|
||||
var wordList = new List<string>();
|
||||
for(int i = 0; i < options.NumWords.GetValueOrDefault(); i++)
|
||||
{
|
||||
var wordIndex = await _cryptoService.RandomNumberAsync(0, listLength);
|
||||
wordList.Add(WordList.EEFLongWordList[wordIndex]);
|
||||
wordList.Add(EEFLongWordList.Instance.List[wordIndex]);
|
||||
}
|
||||
return string.Join(options.WordSeparator, wordList);
|
||||
}
|
||||
|
52
src/Core/Utilities/EEFLongWordList.cs
Normal file
52
src/Core/Utilities/EEFLongWordList.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Bit.Core.Utilities
|
||||
{
|
||||
public class EEFLongWordList
|
||||
{
|
||||
private static volatile EEFLongWordList _uniqueInstance;
|
||||
private static object _syncObj = new object();
|
||||
|
||||
private EEFLongWordList()
|
||||
{
|
||||
List = ReadData().ToList();
|
||||
}
|
||||
|
||||
public static EEFLongWordList Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if(_uniqueInstance == null)
|
||||
{
|
||||
lock(_syncObj)
|
||||
{
|
||||
if(_uniqueInstance == null)
|
||||
{
|
||||
_uniqueInstance = new EEFLongWordList();
|
||||
}
|
||||
}
|
||||
}
|
||||
return (_uniqueInstance);
|
||||
}
|
||||
}
|
||||
|
||||
public List<string> List { get; set; }
|
||||
|
||||
private IEnumerable<string> ReadData()
|
||||
{
|
||||
var assembly = typeof(EEFLongWordList).GetTypeInfo().Assembly;
|
||||
var stream = assembly.GetManifestResourceStream("Bit.Core.Resources.eff_long_word_list.txt");
|
||||
string line;
|
||||
using(var reader = new StreamReader(stream))
|
||||
{
|
||||
while((line = reader.ReadLine()) != null)
|
||||
{
|
||||
yield return line;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user