forked from aliyun/aliyun-oss-ios-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e5cc3c
commit 1f0599d
Showing
46 changed files
with
2,849 additions
and
247 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// NSData+OSS.h | ||
// AliyunOSSSDK | ||
// | ||
// Created by ws on 2023/12/28. | ||
// Copyright © 2023 aliyun. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface NSData (OSS) | ||
|
||
- (NSString *)hexString; | ||
- (NSData *)calculateSha256; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// NSData+OSS.m | ||
// AliyunOSSSDK | ||
// | ||
// Created by ws on 2023/12/28. | ||
// Copyright © 2023 aliyun. All rights reserved. | ||
// | ||
|
||
#import "NSData+OSS.h" | ||
#import <CommonCrypto/CommonDigest.h> | ||
|
||
@implementation NSData (OSS) | ||
|
||
- (NSString *)hexString { | ||
NSMutableString *hexString = [NSMutableString string]; | ||
Byte *byte = (Byte *)[self bytes]; | ||
for (int i = 0; i<[self length]; i++) { | ||
[hexString appendFormat:@"%x", (*(byte + i) >> 4) & 0xf]; | ||
[hexString appendFormat:@"%x", *(byte + i) & 0xf]; | ||
} | ||
return hexString; | ||
} | ||
|
||
- (NSData *)calculateSha256 { | ||
unsigned char *digest = NULL; | ||
|
||
digest = malloc(CC_SHA256_DIGEST_LENGTH * sizeof(unsigned char)); | ||
memset(digest, 0x0, CC_SHA256_DIGEST_LENGTH); | ||
CC_SHA256(self.bytes, (CC_LONG)self.length, digest); | ||
|
||
if (digest) { | ||
NSData *data = [NSData dataWithBytes:digest length:CC_SHA256_DIGEST_LENGTH]; | ||
free(digest); | ||
return data; | ||
} | ||
free(digest); | ||
|
||
return nil; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// NSSet+OSS.h | ||
// AliyunOSSSDK | ||
// | ||
// Created by ws on 2023/12/28. | ||
// Copyright © 2023 aliyun. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
NS_ASSUME_NONNULL_BEGIN | ||
|
||
@interface NSSet (OSS) | ||
|
||
- (NSString *)componentsJoinedByString:(NSString *)separator; | ||
|
||
@end | ||
|
||
NS_ASSUME_NONNULL_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// NSSet+OSS.m | ||
// AliyunOSSSDK | ||
// | ||
// Created by ws on 2023/12/28. | ||
// Copyright © 2023 aliyun. All rights reserved. | ||
// | ||
|
||
#import "NSSet+OSS.h" | ||
|
||
@implementation NSSet (OSS) | ||
|
||
- (NSString *)componentsJoinedByString:(NSString *)separator { | ||
NSMutableString *builder = [NSMutableString new]; | ||
int i = 0; | ||
|
||
for (NSObject *part in self) { | ||
if ([part isKindOfClass:[NSString class]]) { | ||
[builder appendString:(NSString *)part]; | ||
if (i < [self count] - 1) { | ||
[builder appendString:separator]; | ||
} | ||
} | ||
i++; | ||
} | ||
|
||
return builder; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.