Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refine some logics and comments according to ACR service team's review #20981

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions sdk/containers/azcontainerregistry/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
### Bugs Fixed

### Other Changes
* Refine some logics and comments

## 0.2.0 (2023-06-06)

Expand Down
23 changes: 13 additions & 10 deletions sdk/containers/azcontainerregistry/digest_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ type digestValidator interface {
}

func parseDigestValidator(digest string) (digestValidator, error) {
alg := digest[:strings.Index(digest, ":")]
i := strings.Index(digest, ":")
if i < 0 {
return nil, ErrDigestAlgNotSupported
}
alg := digest[:i]
if v, ok := validatorCtors[alg]; ok {
return v(), nil
} else {
return nil, ErrDigestAlgNotSupported
}
return nil, ErrDigestAlgNotSupported
}

type sha256Validator struct {
Expand Down Expand Up @@ -62,15 +65,14 @@ type DigestValidationReader struct {
// NewDigestValidationReader creates a new reader that help you to validate digest when you read manifest or blob data.
func NewDigestValidationReader(digest string, reader io.Reader) (*DigestValidationReader, error) {
validator, err := parseDigestValidator(digest)
if err == nil {
return &DigestValidationReader{
digest: digest,
digestValidator: validator,
reader: reader,
}, nil
} else {
if err != nil {
return nil, err
}
return &DigestValidationReader{
digest: digest,
digestValidator: validator,
reader: reader,
}, nil
}

// Read write to digest validator while read and validate digest when reach EOF.
Expand Down Expand Up @@ -98,6 +100,7 @@ type BlobDigestCalculator struct {
}

// NewBlobDigestCalculator creates a new calculator to help to calculate blob digest when uploading blob.
// You should use a new BlobDigestCalculator each time you upload a blob.
func NewBlobDigestCalculator() *BlobDigestCalculator {
return &BlobDigestCalculator{
h: sha256.New(),
Expand Down