Skip to content

Commit

Permalink
Merge pull request #61 from sgmoore/master
Browse files Browse the repository at this point in the history
Fixes for long passwords on .Net6 and for Tomato app
  • Loading branch information
Delubear authored Jun 17, 2022
2 parents ea347e9 + a6db7a1 commit 5c4088f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 3 additions & 1 deletion GlucoseTray/Services/GlucoseFetchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ private async Task<List<GlucoseResult>> GetResultsFromNightscout(DateTime? timeO
var fetchResult = new GlucoseResult
{
Source = FetchMethod.NightscoutApi,
DateTimeUTC = DateTime.Parse(record.DateString).ToUniversalTime(),
DateTimeUTC = !String.IsNullOrEmpty(record.DateString) ?
DateTime.Parse(record.DateString).ToUniversalTime() :
DateTimeOffset.FromUnixTimeMilliseconds(record.Date).UtcDateTime,
Trend = record.Direction.GetTrend()
};
CalculateValues(fetchResult, record.Sgv);
Expand Down
19 changes: 18 additions & 1 deletion GlucoseTray/Services/StringEncryptionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,24 @@ public static string DecryptString(string cipherText, string passPhrase)
var memoryStream = new MemoryStream(cipherTextBytes);
var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read);
byte[] plainTextBytes = new byte[cipherTextBytes.Length];
int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);

// int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);

// Amended for Dotnet 6.0 and above which now longer guarentees that you will get all
// the bytes you asked for in the first read, so we need to keep reading until the end.
int decryptedByteCount = 0;
byte[] tempBytes = new byte[cipherTextBytes.Length];
do
{
int bytesRead = cryptoStream.Read(tempBytes, 0, tempBytes.Length);
if (bytesRead == 0)
break;

Array.Copy(tempBytes, 0, plainTextBytes, decryptedByteCount, bytesRead);
decryptedByteCount += bytesRead;
}
while (true);

memoryStream.Close();
cryptoStream.Close();
return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
Expand Down
2 changes: 1 addition & 1 deletion GlucoseTray/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"appsettings": {
"Version": "12.0.0"
"Version": "12.0.2"
}
}

0 comments on commit 5c4088f

Please sign in to comment.