Skip to content

Commit 6d840fe

Browse files
Merge pull request #112 from microsoft/user/lemccomb/simplestream
Make the advanced stream handling optional. Use simple retry instead.
2 parents 1e9f3bc + b42197b commit 6d840fe

File tree

13 files changed

+174
-75
lines changed

13 files changed

+174
-75
lines changed

CHANGELOG.md

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
# Changelog
22

3+
## [v1.2.6-pre2](https://github.com/microsoft/CoseSignTool/tree/v1.2.6-pre2) (2024-09-23)
4+
5+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.8...v1.2.6-pre2)
6+
7+
## [v1.2.8](https://github.com/microsoft/CoseSignTool/tree/v1.2.8) (2024-09-23)
8+
9+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.6-pre1...v1.2.8)
10+
11+
**Merged pull requests:**
12+
13+
- Allow outdated and cert chain bug fixes [\#109](https://github.com/microsoft/CoseSignTool/pull/109) ([elantiguamsft](https://github.com/elantiguamsft))
14+
315
## [v1.2.6-pre1](https://github.com/microsoft/CoseSignTool/tree/v1.2.6-pre1) (2024-08-26)
416

517
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.6...v1.2.6-pre1)
@@ -132,7 +144,7 @@
132144

133145
## [v1.2.1-pre2](https://github.com/microsoft/CoseSignTool/tree/v1.2.1-pre2) (2024-03-15)
134146

135-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.2...v1.2.1-pre2)
147+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.1-pre1...v1.2.1-pre2)
136148

137149
**Closed issues:**
138150

@@ -142,25 +154,25 @@
142154

143155
- more granular error codes [\#86](https://github.com/microsoft/CoseSignTool/pull/86) ([lemccomb](https://github.com/lemccomb))
144156

145-
## [v1.2.2](https://github.com/microsoft/CoseSignTool/tree/v1.2.2) (2024-03-12)
157+
## [v1.2.1-pre1](https://github.com/microsoft/CoseSignTool/tree/v1.2.1-pre1) (2024-03-12)
146158

147-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.1-pre1...v1.2.2)
159+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.2...v1.2.1-pre1)
148160

149-
## [v1.2.1-pre1](https://github.com/microsoft/CoseSignTool/tree/v1.2.1-pre1) (2024-03-12)
161+
## [v1.2.2](https://github.com/microsoft/CoseSignTool/tree/v1.2.2) (2024-03-12)
150162

151-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.0-pre1...v1.2.1-pre1)
163+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.1...v1.2.2)
152164

153165
**Merged pull requests:**
154166

155167
- Revert "Add .exe to CoseSignTool NuGet" [\#83](https://github.com/microsoft/CoseSignTool/pull/83) ([elantiguamsft](https://github.com/elantiguamsft))
156168

157-
## [v1.2.0-pre1](https://github.com/microsoft/CoseSignTool/tree/v1.2.0-pre1) (2024-03-07)
169+
## [v1.2.1](https://github.com/microsoft/CoseSignTool/tree/v1.2.1) (2024-03-07)
158170

159-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.1...v1.2.0-pre1)
171+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.0-pre1...v1.2.1)
160172

161-
## [v1.2.1](https://github.com/microsoft/CoseSignTool/tree/v1.2.1) (2024-03-07)
173+
## [v1.2.0-pre1](https://github.com/microsoft/CoseSignTool/tree/v1.2.0-pre1) (2024-03-07)
162174

163-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.exeTest...v1.2.1)
175+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.2.exeTest...v1.2.0-pre1)
164176

165177
**Merged pull requests:**
166178

@@ -176,19 +188,19 @@
176188

177189
## [v1.2.0](https://github.com/microsoft/CoseSignTool/tree/v1.2.0) (2024-03-04)
178190

179-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.7-pre3...v1.2.0)
191+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.8...v1.2.0)
180192

181193
**Merged pull requests:**
182194

183195
- Update Nuspec for CoseIndirectSignature [\#80](https://github.com/microsoft/CoseSignTool/pull/80) ([elantiguamsft](https://github.com/elantiguamsft))
184196

185-
## [v1.1.7-pre3](https://github.com/microsoft/CoseSignTool/tree/v1.1.7-pre3) (2024-03-02)
197+
## [v1.1.8](https://github.com/microsoft/CoseSignTool/tree/v1.1.8) (2024-03-02)
186198

187-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.8...v1.1.7-pre3)
199+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.7-pre3...v1.1.8)
188200

189-
## [v1.1.8](https://github.com/microsoft/CoseSignTool/tree/v1.1.8) (2024-03-02)
201+
## [v1.1.7-pre3](https://github.com/microsoft/CoseSignTool/tree/v1.1.7-pre3) (2024-03-02)
190202

191-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.7-pre2...v1.1.8)
203+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.7-pre2...v1.1.7-pre3)
192204

193205
**Merged pull requests:**
194206

@@ -224,31 +236,31 @@
224236

225237
## [v1.1.6](https://github.com/microsoft/CoseSignTool/tree/v1.1.6) (2024-02-07)
226238

227-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.5...v1.1.6)
239+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.4-pre1...v1.1.6)
228240

229241
**Merged pull requests:**
230242

231243
- Only hit iterator once [\#75](https://github.com/microsoft/CoseSignTool/pull/75) ([JeromySt](https://github.com/JeromySt))
232244

233-
## [v1.1.5](https://github.com/microsoft/CoseSignTool/tree/v1.1.5) (2024-01-31)
245+
## [v1.1.4-pre1](https://github.com/microsoft/CoseSignTool/tree/v1.1.4-pre1) (2024-01-31)
234246

235-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.4-pre1...v1.1.5)
247+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.5...v1.1.4-pre1)
236248

237-
## [v1.1.4-pre1](https://github.com/microsoft/CoseSignTool/tree/v1.1.4-pre1) (2024-01-31)
249+
## [v1.1.5](https://github.com/microsoft/CoseSignTool/tree/v1.1.5) (2024-01-31)
238250

239-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.3-pre1...v1.1.4-pre1)
251+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.4...v1.1.5)
240252

241253
**Merged pull requests:**
242254

243255
- write validation output to standard out [\#74](https://github.com/microsoft/CoseSignTool/pull/74) ([elantiguamsft](https://github.com/elantiguamsft))
244256

245-
## [v1.1.3-pre1](https://github.com/microsoft/CoseSignTool/tree/v1.1.3-pre1) (2024-01-26)
257+
## [v1.1.4](https://github.com/microsoft/CoseSignTool/tree/v1.1.4) (2024-01-26)
246258

247-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.4...v1.1.3-pre1)
259+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.3-pre1...v1.1.4)
248260

249-
## [v1.1.4](https://github.com/microsoft/CoseSignTool/tree/v1.1.4) (2024-01-26)
261+
## [v1.1.3-pre1](https://github.com/microsoft/CoseSignTool/tree/v1.1.3-pre1) (2024-01-26)
250262

251-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.3...v1.1.4)
263+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.3...v1.1.3-pre1)
252264

253265
**Merged pull requests:**
254266

@@ -260,39 +272,39 @@
260272

261273
## [v1.1.2-pre1](https://github.com/microsoft/CoseSignTool/tree/v1.1.2-pre1) (2024-01-24)
262274

263-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.2...v1.1.2-pre1)
275+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.1-pre2...v1.1.2-pre1)
264276

265277
**Merged pull requests:**
266278

267279
- Updating snk for internal package compatibility [\#72](https://github.com/microsoft/CoseSignTool/pull/72) ([elantiguamsft](https://github.com/elantiguamsft))
268280

269-
## [v1.1.2](https://github.com/microsoft/CoseSignTool/tree/v1.1.2) (2024-01-18)
281+
## [v1.1.1-pre2](https://github.com/microsoft/CoseSignTool/tree/v1.1.1-pre2) (2024-01-18)
270282

271-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.1-pre2...v1.1.2)
283+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.2...v1.1.1-pre2)
272284

273-
## [v1.1.1-pre2](https://github.com/microsoft/CoseSignTool/tree/v1.1.1-pre2) (2024-01-18)
285+
## [v1.1.2](https://github.com/microsoft/CoseSignTool/tree/v1.1.2) (2024-01-18)
274286

275-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.1-pre1...v1.1.1-pre2)
287+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.1-pre1...v1.1.2)
276288

277289
**Merged pull requests:**
278290

279291
- Add logging for failure paths as well as some various improvements to the code base. [\#71](https://github.com/microsoft/CoseSignTool/pull/71) ([JeromySt](https://github.com/JeromySt))
280292

281293
## [v1.1.1-pre1](https://github.com/microsoft/CoseSignTool/tree/v1.1.1-pre1) (2024-01-17)
282294

283-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.0-pre7...v1.1.1-pre1)
295+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.1...v1.1.1-pre1)
284296

285297
**Merged pull requests:**
286298

287299
- Move CreateChangelog to after build in PR build [\#70](https://github.com/microsoft/CoseSignTool/pull/70) ([lemccomb](https://github.com/lemccomb))
288300

289-
## [v1.1.0-pre7](https://github.com/microsoft/CoseSignTool/tree/v1.1.0-pre7) (2024-01-12)
301+
## [v1.1.1](https://github.com/microsoft/CoseSignTool/tree/v1.1.1) (2024-01-12)
290302

291-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.1...v1.1.0-pre7)
303+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.0-pre7...v1.1.1)
292304

293-
## [v1.1.1](https://github.com/microsoft/CoseSignTool/tree/v1.1.1) (2024-01-12)
305+
## [v1.1.0-pre7](https://github.com/microsoft/CoseSignTool/tree/v1.1.0-pre7) (2024-01-12)
294306

295-
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.0-pre6...v1.1.1)
307+
[Full Changelog](https://github.com/microsoft/CoseSignTool/compare/v1.1.0-pre6...v1.1.0-pre7)
296308

297309
**Closed issues:**
298310

CoseHandler.Tests/CoseExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
namespace CoseSignUnitTests;

CoseHandler.Tests/Usings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
global using System.Formats.Cbor;

CoseHandler/CoseHandler.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ internal static ReadOnlyMemory<byte> SignInternal(
292292
try
293293
{
294294
// Read payload file to stream if provided.
295-
payloadStream ??= payloadFile?.GetStreamResilient();
295+
//payloadStream ??= payloadFile?.GetStreamResilient();
296+
payloadStream ??= payloadFile?.GetStreamBasic(30);
296297

297298
// Sign the payload.
298299
//#pragma warning disable CS8604 // Possible null reference argument: False positive on contentType param which has a default value.
@@ -622,8 +623,8 @@ internal static ValidationResult ValidateInternal(
622623
try
623624
{
624625
// Load file content if provided.
625-
payloadStream ??= payloadFile?.GetStreamResilient();
626-
signatureStream ??= signatureFile?.GetStreamResilient();
626+
payloadStream ??= payloadFile?.GetStreamBasic(30);
627+
signatureStream ??= signatureFile?.GetStreamBasic(30);
627628
signatureBytes ??= signatureStream!.GetBytes().AsMemory();
628629

629630
// List for collecting any validation errors we hit.

CoseHandler/CoseHandler.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
</PropertyGroup>
3737

3838
<!--Package references-->
39-
<ItemGroup>
40-
</ItemGroup>
4139

4240
<!--Project references-->
4341
<ItemGroup>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace CoseX509;
5+
internal class EmptyFileException : IOException
6+
{
7+
/// <summary>
8+
/// Initializes an instance of the <see cref="EmptyFileException"/> class for the specified file.
9+
/// </summary>
10+
/// <param name="fileName">The file name.</param>
11+
/// <param name="message">The error text.</param>
12+
public EmptyFileException(string fileName) : base($"The file at {fileName} was empty or still being written.") { }
13+
14+
/// <summary>
15+
/// Initializes an instance of the <see cref="EmptyFileException"/> class for the specified file and adds an error message.
16+
/// </summary>
17+
/// <param name="fileName">The file name.</param>
18+
/// <param name="message">The error text.</param>
19+
public EmptyFileException(string fileName, string message) : base($"{message}: {fileName}") { }
20+
}

CoseHandler/Extensions/FileInfoExtensions.cs

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,48 @@ public static class FileInfoExtensions
1414
/// <returns>The file content.</returns>
1515
public static byte[] GetBytesResilient(this FileInfo f, OutputTarget? writeTo = null, int maxWaitTime = 5) => GetBytesOrStream(f, false, writeTo, maxWaitTime).Item1!;
1616

17+
/// <summary>
18+
/// Loads the content of a file into a <see cref="FileStream"/> with retries to make sure the file loads successfully and is not empty.
19+
/// </summary>
20+
/// <param name="f">The file to read.</param>
21+
/// <param name="writeTo">The output target to write status messages to. Default is STDOUT.</param>
22+
/// <param name="maxWaitTime">The maximum number of seconds to wait for file availability. This value is used up to four times.</param>
23+
/// <returns>The file content.</returns>
24+
public static FileStream? GetStreamBasic(this FileInfo f, int maxWaitTime = 30, OutputTarget? writeTo = null)
25+
{
26+
Exception? ex = null;
27+
DateTime startTime = DateTime.Now;
28+
int counter = 0;
29+
writeTo ??= OutputTarget.StdOut;
30+
while (SecondsSince(startTime) < 30)
31+
{
32+
try
33+
{
34+
if (!f.Exists) { throw new FileNotFoundException(); }
35+
else if (f.Length == 0) { throw new EmptyFileException(f.FullName); }
36+
return f.OpenRead();
37+
}
38+
catch (Exception e)
39+
{
40+
if (counter % 4 == 0) { writeTo.Write("."); }
41+
ex = e;
42+
Thread.Sleep(250);
43+
counter++;
44+
}
45+
}
46+
47+
throw ex!;
48+
}
49+
50+
1751
/// <summary>
1852
/// Loads the content of a file into a <see cref="FileStream"/> after making sure the file exists, is not empty, and is not locked by another process.
1953
/// </summary>
2054
/// <param name="f">The file to read.</param>
2155
/// <param name="writeTo">The output target to write status messages to. Default is STDOUT.</param>
2256
/// <param name="maxWaitTime">The maximum number of seconds to wait for file availability. This value is used up to four times.</param>
2357
/// <returns>The file content.</returns>
24-
public static FileStream? GetStreamResilient(this FileInfo f, OutputTarget? writeTo = null, int maxWaitTime = 5) => GetBytesOrStream(f, true, writeTo, maxWaitTime).Item2;
58+
public static FileStream? GetStreamResilient(this FileInfo f, int maxWaitTime = 5, OutputTarget? writeTo = null) => GetBytesOrStream(f, true, writeTo, maxWaitTime).Item2;
2559

2660
private static (byte[]?, FileStream?) GetBytesOrStream(FileInfo f, bool isStream, OutputTarget? writer, int maxWaitTime)
2761
{
@@ -46,7 +80,7 @@ private static (byte[]?, FileStream?) GetBytesOrStream(FileInfo f, bool isStream
4680

4781
if (OutOfTime(startTime, maxWaitTime))
4882
{
49-
throw new IOException($"File is empty after {SecondsSince(startTime)} seconds.");
83+
throw new EmptyFileException(f.FullName, $"File is empty after {SecondsSince(startTime)} seconds.");
5084
}
5185
}
5286

CoseHandler/Extensions/ObjectExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
namespace CoseX509;

CoseSign1.Certificates/Local/Validators/X509Certificate2MessageValidator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
namespace CoseSign1.Certificates.Local.Validators;

CoseSign1/Exceptions/CoseSigningException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation.
1+
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

44
namespace CoseSign1.Abstractions.Exceptions;

0 commit comments

Comments
 (0)