Skip to content

Commit

Permalink
refine some logics and comments according to ACR service team's review (
Browse files Browse the repository at this point in the history
  • Loading branch information
tadelesh authored Jun 8, 2023
1 parent ca31ac1 commit fab98b0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
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

0 comments on commit fab98b0

Please sign in to comment.