signer_access_key.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Licensed under the Apache License, Version 2.0 (the "License");
  3. * you may not use this file except in compliance with the License.
  4. * You may obtain a copy of the License at
  5. *
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an "AS IS" BASIS,
  10. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. * See the License for the specific language governing permissions and
  12. * limitations under the License.
  13. */
  14. package signers
  15. import (
  16. "github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
  17. )
  18. type AccessKeySigner struct {
  19. credential *credentials.AccessKeyCredential
  20. }
  21. func (signer *AccessKeySigner) GetExtraParam() map[string]string {
  22. return nil
  23. }
  24. func NewAccessKeySigner(credential *credentials.AccessKeyCredential) *AccessKeySigner {
  25. return &AccessKeySigner{
  26. credential: credential,
  27. }
  28. }
  29. func (*AccessKeySigner) GetName() string {
  30. return "HMAC-SHA1"
  31. }
  32. func (*AccessKeySigner) GetType() string {
  33. return ""
  34. }
  35. func (*AccessKeySigner) GetVersion() string {
  36. return "1.0"
  37. }
  38. func (signer *AccessKeySigner) GetAccessKeyId() (accessKeyId string, err error) {
  39. return signer.credential.AccessKeyId, nil
  40. }
  41. func (signer *AccessKeySigner) Sign(stringToSign, secretSuffix string) string {
  42. secret := signer.credential.AccessKeySecret + secretSuffix
  43. return ShaHmac1(stringToSign, secret)
  44. }