Skip to content
This repository was archived by the owner on Oct 17, 2024. It is now read-only.

Documentation of usage. #36

Merged
merged 5 commits into from
Jan 20, 2018
Merged

Documentation of usage. #36

merged 5 commits into from
Jan 20, 2018

Conversation

hoylen
Copy link
Contributor

@hoylen hoylen commented Jun 28, 2017

Added documentation in the README file on how to use this package.

This should make it easier for people to use it.

README.md Outdated
@@ -1,14 +1,110 @@
# Library of cryptographic functions for Dart
# Cryptographic digest functions for Dart
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Digest" is kind of confusing term here—in my experience, "hash" is used much more widely in practice. Can you consistently refer to them as "hashes" unless you're specifically talking about the Digest class?

README.md Outdated
* Converting a Base 64 encoded String into list of bytes.
* SHA-1
* SHA-256
* HMAC (i.e. HMAC-MD5, HMAC-SHA1, HMAC-SHA256)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to link these to the relevant API documentation.

README.md Outdated
Invoke the `convert` method, passing the input data as a sequence of
bytes (i.e. `List<int>`). It returns a `Digest` object, where the
digest value can be obtained as bytes in a `List<int>` or encoded in
hexadecimal as a `String`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These paragraphs are pretty verbose. Maybe "Use sha256.convert(), sha1.convert(), or md5.convert() to hash a list of bytes." (with links to the API docs). Generally, I prefer including the more detailed usage information in the code snippet, since it's easy for users to see how it's invoked there.

README.md Outdated
import 'package:crypto/crypto.dart';
import 'dart:convert'; // for the UTF8.encode method

...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I try to make my example code snippets valid stand-alone Dart programs if possible, which means writing out a main() method.

README.md Outdated
Do not use the `codeUnits` property of a `String`, unless it is
_guaranteed_ the string will never contain characters outside the
range of 0-255. Even then, characters in the range of 128-255 might
produce the wrong result.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary here—it's not really a property of this library, but of the general way Dart handles binary data and strings.

README.md Outdated
range of 0-255. Even then, characters in the range of 128-255 might
produce the wrong result.

### Digest on chunked input
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this stuff comes from the core library's Converter API. I'm not sure it's worth giving a full tutorial for it here, as opposed to just linking to that documentation (and improving it if necessary).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you missed this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "tutorial" was all deleted.

@hoylen
Copy link
Contributor Author

hoylen commented Jun 30, 2017

All requested changes have been performed.

Links to the relevant API documentation have been added for the variables/classes in a new paragraph just before the first example. This is better because the algorithms are not the same as a particular implementation of the algorithms. And the list is cleaner too.

README.md Outdated

The variables [`sha256`][sha256], [`sha1`][sha1], and [`md5`][md5] are
instances of the [`Sha256`][Sha256], [`Sha1`][Sha1], and [`MD5`][MD5]
classes, respectively.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this sentence is particularly useful. It's easy for users to look at the documentation and see the class structure, but in terms of real-world usage they're going to be dealing exclusively with the constants themselves.

README.md Outdated
Or use the `sha1` or `md5` properties to use those other digest
algorithms.
Use `sha256.convert()`, `sha1.convert()`, or `md5.convert()` to hash a
list of bytes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These still need links.

README.md Outdated

print("HMAC digest as bytes: ${digest.bytes}");
print("HMAC digest as hex string: $digest");
}
```

## Test status
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove this and everything below it? It's inaccurate and redundant at this point.

README.md Outdated
range of 0-255. Even then, characters in the range of 128-255 might
produce the wrong result.

### Digest on chunked input
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you missed this comment.

@hoylen
Copy link
Contributor Author

hoylen commented Jun 30, 2017

Done.

@isoos isoos mentioned this pull request Nov 27, 2017
@isoos
Copy link

isoos commented Nov 27, 2017

/ping

I think this PR will be very useful. E.g. I was searching for 'sha256' on pub, and the crypto package didn't turn up. With the new doc it should.

@kevmoo
Copy link
Contributor

kevmoo commented Jan 20, 2018

This is great progress. If there's any cleanup, we can do it in a follow-up, PR.

@kevmoo kevmoo merged commit 69c50ed into dart-archive:master Jan 20, 2018
mosuem pushed a commit to dart-lang/core that referenced this pull request Oct 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

Successfully merging this pull request may close these issues.

5 participants