-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved overall security of keystores
- Loading branch information
Showing
9 changed files
with
180 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
|
||
namespace System.Linq | ||
{ | ||
/// <inheritdoc/> | ||
public static partial class Enumerable | ||
{ | ||
/// <summary> | ||
/// Split the elements of a sequence into chunks of size at most <paramref name="size"/>. | ||
/// </summary> | ||
/// <remarks> | ||
/// Every chunk except the last will be of size <paramref name="size"/>. | ||
/// The last chunk will contain the remaining elements and may be of a smaller size. | ||
/// </remarks> | ||
/// <param name="source"> | ||
/// An <see cref="IEnumerable{T}"/> whose elements to chunk. | ||
/// </param> | ||
/// <param name="size"> | ||
/// Maximum size of each chunk. | ||
/// </param> | ||
/// <typeparam name="TSource"> | ||
/// The type of the elements of source. | ||
/// </typeparam> | ||
/// <returns> | ||
/// An <see cref="IEnumerable{T}"/> that contains the elements the input sequence split into chunks of size <paramref name="size"/>. | ||
/// </returns> | ||
/// <exception cref="ArgumentNullException"> | ||
/// <paramref name="source"/> is null. | ||
/// </exception> | ||
/// <exception cref="ArgumentOutOfRangeException"> | ||
/// <paramref name="size"/> is below 1. | ||
/// </exception> | ||
public static IEnumerable<TSource[]> Chunk<TSource>(this IEnumerable<TSource> source, int size) | ||
{ | ||
if (source == null) | ||
{ | ||
throw new ArgumentNullException("source"); | ||
} | ||
|
||
if (size < 1) | ||
{ | ||
throw new ArgumentOutOfRangeException("size"); | ||
} | ||
|
||
return ChunkIterator(source, size); | ||
} | ||
|
||
private static IEnumerable<TSource[]> ChunkIterator<TSource>(IEnumerable<TSource> source, int size) | ||
{ | ||
using (IEnumerator<TSource> e = source.GetEnumerator()) | ||
{ | ||
while (e.MoveNext()) | ||
{ | ||
TSource[] chunk = new TSource[size]; | ||
chunk[0] = e.Current; | ||
|
||
int i = 1; | ||
for (; i < chunk.Length && e.MoveNext(); i++) | ||
{ | ||
chunk[i] = e.Current; | ||
} | ||
|
||
if (i == chunk.Length) | ||
{ | ||
yield return chunk; | ||
} | ||
else | ||
{ | ||
Array.Resize(ref chunk, i); | ||
yield return chunk; | ||
yield break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.