Skip to content

Commit c57b850

Browse files
committed
Removed FormC normalization
1 parent 76ba871 commit c57b850

4 files changed

Lines changed: 8 additions & 18 deletions

File tree

src/Core/SecureFolderFS.Core.FileSystem/Helpers/Paths/Abstract/AbstractPathHelpers.Names.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static async Task<string> EncryptNameAsync(string plaintextName, IFolder
4747
var directoryId = AllocateDirectoryId(specifics.Security, ciphertextName);
4848
var result = await GetDirectoryIdAsync(ciphertextParentFolder, specifics, directoryId, cancellationToken);
4949

50-
var normalizedName = NoCipherExtensionNormalizedName(ciphertextName);
50+
var normalizedName = RemoveCiphertextExtension(ciphertextName);
5151
return specifics.Security.NameCrypt.DecryptName(normalizedName, result ? directoryId : ReadOnlySpan<byte>.Empty);
5252
}
5353
catch (Exception)
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using SecureFolderFS.Core.Cryptography;
2-
using System;
1+
using System;
32
using System.IO;
4-
using System.Text;
3+
using SecureFolderFS.Core.Cryptography;
54

65
namespace SecureFolderFS.Core.FileSystem.Helpers.Paths.Abstract
76
{
@@ -21,24 +20,15 @@ public static byte[] AllocateDirectoryId(Security security, string? path = null)
2120
return new byte[Constants.DIRECTORY_ID_SIZE];
2221
}
2322

24-
public static ReadOnlySpan<char> NoCipherExtensionNormalizedName(string ciphertextName)
23+
public static ReadOnlySpan<char> RemoveCiphertextExtension(string ciphertextName)
2524
{
2625
// Do NOT use Path.GetFileNameWithoutExtension - after APFS or ContentProvider NFD-decomposes Base4K
2726
// codepoints, the string may contain spurious dot-like characters that confuse the
2827
// path parser, causing it to truncate mid-ciphertext.
2928
// Strip the known extension manually instead.
30-
var nameWithoutExtension = ciphertextName.EndsWith(Constants.Names.ENCRYPTED_FILE_EXTENSION, StringComparison.Ordinal)
29+
return ciphertextName.EndsWith(Constants.Names.ENCRYPTED_FILE_EXTENSION, StringComparison.Ordinal)
3130
? ciphertextName.AsSpan(0, ciphertextName.Length - Constants.Names.ENCRYPTED_FILE_EXTENSION.Length)
3231
: ciphertextName.AsSpan();
33-
34-
var normalizedLength = nameWithoutExtension.GetNormalizedLength(NormalizationForm.FormC);
35-
var normalized = new char[normalizedLength];
36-
37-
// NFC-normalize before decoding
38-
if (nameWithoutExtension.TryNormalize(normalized, out var written, NormalizationForm.FormC))
39-
return normalized.AsSpan(0, written);
40-
41-
return nameWithoutExtension;
4232
}
4333
}
4434
}

src/Core/SecureFolderFS.Core.FileSystem/Helpers/Paths/Native/NativePathHelpers.Names.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public static string EncryptName(string plaintextName, string plaintextParentFol
4242
return ciphertextName;
4343

4444
var result = GetDirectoryId(ciphertextParentFolder, specifics, expendableDirectoryId);
45-
var normalizedName = AbstractPathHelpers.NoCipherExtensionNormalizedName(ciphertextName);
45+
var normalizedName = AbstractPathHelpers.RemoveCiphertextExtension(ciphertextName);
4646

4747
return specifics.Security.NameCrypt.DecryptName(normalizedName, result ? expendableDirectoryId : ReadOnlySpan<byte>.Empty);
4848
}

src/Core/SecureFolderFS.Core.FileSystem/Helpers/RecycleBin/Abstract/AbstractRecycleBinHelpers.Operational.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public static async Task RestoreAsync(IStorableChild recycleBinItem, IModifiable
9090
{
9191
// Destination folder is the same as the original destination
9292
// The same name could be used since the Directory IDs match
93-
var ciphertextName = Path.ChangeExtension(await AbstractPathHelpers.EncryptNameAsync(plaintextOriginalName, ciphertextDestinationFolder, specifics, cancellationToken), Constants.Names.ENCRYPTED_FILE_EXTENSION);
93+
var ciphertextName = await AbstractPathHelpers.EncryptNameAsync(plaintextOriginalName, ciphertextDestinationFolder, specifics, cancellationToken);
9494

9595
// Get an available name if the destination already exists
9696
ciphertextName = await GetAvailableDestinationNameAsync(ciphertextDestinationFolder, ciphertextName, plaintextOriginalName, specifics, cancellationToken);
@@ -235,7 +235,7 @@ private static async Task<string> GetAvailableDestinationNameAsync(IFolder ciphe
235235
do
236236
{
237237
var newPlaintextName = $"{nameWithoutExtension} ({suffix}){extension}";
238-
ciphertextName = Path.ChangeExtension(await AbstractPathHelpers.EncryptNameAsync(newPlaintextName, ciphertextDestinationFolder, specifics, cancellationToken), Constants.Names.ENCRYPTED_FILE_EXTENSION);
238+
ciphertextName = await AbstractPathHelpers.EncryptNameAsync(newPlaintextName, ciphertextDestinationFolder, specifics, cancellationToken);
239239
existing = await ciphertextDestinationFolder.TryGetFirstByNameAsync(ciphertextName, cancellationToken);
240240
suffix++;
241241
} while (existing is not null);

0 commit comments

Comments
 (0)