Skip to content

Commit

Permalink
Adds API documentation (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Cornell authored Jun 3, 2020
1 parent 8583eaf commit 688ddce
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Amazon.IonHashDotnet/CryptoIonHasherProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

namespace Amazon.IonHashDotnet
{
/// <summary>
/// IIonHasherProvider implementation based on System.Security.Cryptography.
/// </summary>
public class CryptoIonHasherProvider : IIonHasherProvider
{
private readonly string algorithm;
Expand Down
20 changes: 20 additions & 0 deletions Amazon.IonHashDotnet/IIonHashReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,28 @@ namespace Amazon.IonHashDotnet
{
using Amazon.IonDotnet;

/// <summary>
/// IIonReader extension that provides the hash of the IonValue just nexted
/// past or stepped out of, as defined by the Amazon Ion Hash Specification.
/// <p/>
/// Implementations of this interface are not thread-safe.
/// </summary>
/// <see cref="IIonReader"/>
public interface IIonHashReader : IIonReader
{
/// <summary>
/// Provides the hash of the Ion value just nexted past or stepped out of;
/// hashes of partial Ion values are not provided. If there is no current
/// hash value, returns an empty array.
/// <p/>
/// Implementations must calculate the hash independently of how the Ion
/// is traversed (e.g., the hash of a container must be identical whether
/// the caller skips over it, steps into it, or any combination thereof).
/// </summary>
/// <returns>
/// Array of bytes representing the hash of the Ion value just
/// nexted past; if there is no hash, returns an empty array.
/// </returns>
byte[] Digest();
}
}
16 changes: 16 additions & 0 deletions Amazon.IonHashDotnet/IIonHashWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,24 @@ namespace Amazon.IonHashDotnet
{
using Amazon.IonDotnet;

/// <summary>
/// IIonWriter extension that provides the hash of the Ion value just written
/// or stepped out of, as defined by the Amazon Ion Hash Specification.
/// <p/>
/// Implementations of this interface are not thread-safe.
/// </summary>
/// <see cref="IIonWriter"/>
public interface IIonHashWriter : IIonWriter
{
/// <summary>
/// Provides the hash of the Ion value just nexted past or stepped out of;
/// hashes of partial Ion values are not provided. If there is no current
/// hash value, returns an empty array.
/// </summary>
/// <returns>
/// Array of bytes representing the hash of the Ion value just
/// written or stepped out of; if there is no hash, returns an empty array.
/// </returns>
byte[] Digest();
}
}
13 changes: 13 additions & 0 deletions Amazon.IonHashDotnet/IIonHasher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,23 @@

namespace Amazon.IonHashDotnet
{
/// <summary>
/// User-provided hash function that is required by the Amazon Ion Hash
/// Specification.
/// </summary>
public interface IIonHasher
{
/// <summary>
/// Updates the hash with the specified array of bytes.
/// </summary>
/// <param name="bytes">The bytes to hash.</param>
void Update(byte[] bytes);

/// <summary>
/// Returns the computed hash bytes and resets any internal state
/// so the hasher may be reused.
/// </summary>
/// <returns>The computed hash bytes.</returns>
byte[] Digest();
}
}
10 changes: 10 additions & 0 deletions Amazon.IonHashDotnet/IIonHasherProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@

namespace Amazon.IonHashDotnet
{
/// <summary>
/// An implementation of this interface provides IIonHasher instances
/// to an Ion hash implementation as needed.
/// <p/>
/// Implementations must be thread-safe.
/// </summary>
public interface IIonHasherProvider
{
/// <summary>
/// Produces a new IIonHasher instance.
/// </summary>
/// <returns>The new IIonHasher instance.</returns>
IIonHasher NewHasher();
}
}
3 changes: 3 additions & 0 deletions Amazon.IonHashDotnet/IonHashException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ namespace Amazon.IonHashDotnet
using System;
using Amazon.IonDotnet;

/// <summary>
/// Thrown for unexpected or error conditions while hashing Ion data.
/// </summary>
public class IonHashException : IonException
{
public IonHashException(Exception inner)
Expand Down
24 changes: 24 additions & 0 deletions Amazon.IonHashDotnet/IonHashReaderBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ namespace Amazon.IonHashDotnet
using System;
using Amazon.IonDotnet;

/// <summary>
/// Build a new <see cref="IIonHashReader"/> for the given <see cref="IIonReader"/>
/// and <see cref="IIonHasherProvider"/>.
/// <p/>
/// Instances of this class are not thread-safe.
/// </summary>
public class IonHashReaderBuilder
{
private IIonHasherProvider hasherProvider = null;
Expand All @@ -28,23 +34,41 @@ private IonHashReaderBuilder()
{
}

/// <summary>
/// The standard builder of <see cref="IonHashReaderBuilder"/>s.
/// </summary>
/// <returns>The standard builder.</returns>
public static IonHashReaderBuilder Standard()
{
return new IonHashReaderBuilder();
}

/// <summary>
/// Specifies the reader to compute hashes over.
/// </summary>
/// <param name="reader">The IIonReader to compute hasher over.</param>
/// <returns>This builder.</returns>
public IonHashReaderBuilder WithReader(IIonReader reader)
{
this.reader = reader;
return this;
}

/// <summary>
/// Specifies the hasher provider to use.
/// </summary>
/// <param name="hasherProvider">The IIonHasherProvider instance to use.</param>
/// <returns>This builder.</returns>
public IonHashReaderBuilder WithHasherProvider(IIonHasherProvider hasherProvider)
{
this.hasherProvider = hasherProvider;
return this;
}

/// <summary>
/// Constructs a new IIonHashReader, which decorates the IIonReader with hashes.
/// </summary>
/// <returns>A new IIonHashReader object.</returns>
public IIonHashReader Build()
{
if (this.hasherProvider == null || this.reader == null)
Expand Down
24 changes: 24 additions & 0 deletions Amazon.IonHashDotnet/IonHashWriterBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ namespace Amazon.IonHashDotnet
using System;
using Amazon.IonDotnet;

/// <summary>
/// Build a new <see cref="IIonHashWriter"/> for the given <see cref="IIonWriter"/>
/// and <see cref="IIonHasherProvider"/>.
/// <p/>
/// Instances of this class are not thread-safe.
/// </summary>
public class IonHashWriterBuilder
{
private IIonHasherProvider hasherProvider;
Expand All @@ -28,23 +34,41 @@ private IonHashWriterBuilder()
{
}

/// <summary>
/// The standard builder of <see cref="IonHashWriterBuilder"/>s.
/// </summary>
/// <returns>The standard builder.</returns>
public static IonHashWriterBuilder Standard()
{
return new IonHashWriterBuilder();
}

/// <summary>
/// Specifies the writer to compute hashes over.
/// </summary>
/// <param name="writer">The IIonWriter to compute hashes over.</param>
/// <returns>This builder.</returns>
public IonHashWriterBuilder WithWriter(IIonWriter writer)
{
this.writer = writer;
return this;
}

/// <summary>
/// Specifies the hasher provider to use.
/// </summary>
/// <param name="hasherProvider">The IIonHasherProvider instance to use.</param>
/// <returns>This builder.</returns>
public IonHashWriterBuilder WithHasherProvider(IIonHasherProvider hasherProvider)
{
this.hasherProvider = hasherProvider;
return this;
}

/// <summary>
/// Constructs a new IIonHashWriter, which decorates the IIonWriter with hashes.
/// </summary>
/// <returns>A new IIonHashWriter object.</returns>
public IIonHashWriter Build()
{
if (this.hasherProvider == null || this.writer == null)
Expand Down

0 comments on commit 688ddce

Please sign in to comment.