Skip to content

Commit

Permalink
Merge pull request #64 from hyperledger/fix/string-to-hex
Browse files Browse the repository at this point in the history
Fix wrong pointer logic in keypair obj-c
  • Loading branch information
MukhinAlexey authored May 12, 2018
2 parents 64e6327 + 921eaca commit 0512600
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 12 deletions.
8 changes: 7 additions & 1 deletion SwiftyIroha.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0930;
LastUpgradeCheck = 0920;
LastUpgradeCheck = 0930;
ORGANIZATIONNAME = Soramitsu;
TargetAttributes = {
8A37473420A0E14F005D623F = {
Expand Down Expand Up @@ -901,6 +901,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ADDRESS_SANITIZER_CONTAINER_OVERFLOW = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
Expand All @@ -922,6 +923,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ADDRESS_SANITIZER_CONTAINER_OVERFLOW = YES;
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
Expand Down Expand Up @@ -951,13 +953,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down Expand Up @@ -1021,13 +1025,15 @@
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
Expand Down
2 changes: 1 addition & 1 deletion SwiftyIroha/ObjC++/ModelCrypto/Keypair/IRKeypair.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

@interface IRKeypair : NSObject {
@private
struct KeypairImpl* keypairImpl;
struct KeypairImpl *keypairImpl;
}

@property NSString* privateKey;
Expand Down
16 changes: 13 additions & 3 deletions SwiftyIroha/ObjC++/ModelCrypto/Keypair/IRKeypair.mm
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,31 @@
@implementation IRKeypair

- (id)initWithPublicKey: (NSString*)publicKey
withPrivateKey: (NSString*)privateKey {
withPrivateKey: (NSString*)privateKey {
self = [super init];
if (self) {
self.privateKey = privateKey;
self.publicKey = publicKey;
self.privateKey = privateKey;
string publicKeyCpp = [self getStringCppFromStringObjC:publicKey];
string privateKeyCpp = [self getStringCppFromStringObjC:privateKey];
self->keypairImpl = new KeypairImpl(Keypair(PublicKey(Blob::fromHexString(publicKeyCpp)),
PrivateKey(Blob::fromHexString(privateKeyCpp))));
}
return self;
}

-(void)setKeypair:(struct KeypairImpl*)keypair {
keypairImpl = keypair;
keypairImpl = new KeypairImpl(keypair->keypairCpp);
}

-(struct KeypairImpl)getKeypair {
return *(keypairImpl);
}

-(string)getStringCppFromStringObjC:(NSString*)stringObjC {
string stringCpp = string([stringObjC UTF8String],
[stringObjC lengthOfBytesUsingEncoding:NSUTF8StringEncoding]);
return stringCpp;
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,13 @@ -(IRModelTransactionBuilder*)createAccountWithAccountName:(NSString*)accountName
withPublicKey:(IRPublicKey*)publicKey {
string accountNameCpp = [self getStringCppFromStringObjC:accountName];
string domainIdCpp = [self getStringCppFromStringObjC:domainId];
NSData *data = [self dataFromHexString:publicKey.value];
string publicKeyCpp = [self getStringCppFromStringObjC:publicKey.value];

PublicKey publicKeyCpp = PublicKey((char*)([data bytes]));
transactionBuilderImpl->transactionBuilderCpp =
transactionBuilderImpl->transactionBuilderCpp.createAccount(accountNameCpp,
domainIdCpp,
publicKeyCpp);
PublicKey(Blob::fromHexString(publicKeyCpp)));
// NSLog(@"%@", data);
return self;
}

Expand Down Expand Up @@ -287,7 +287,7 @@ -(string)getStringCppFromStringObjC:(NSString*)stringObjC {
return stringCpp;
}

- (NSData *)dataFromHexString:(NSString *) string {
- (NSData*)dataFromHexString:(NSString*) string {
[string stringByReplacingOccurrencesOfString:@" " withString:@""];
NSMutableData* dataValue = [[NSMutableData alloc] init];
unsigned char byte;
Expand Down
1 change: 1 addition & 0 deletions SwiftyIroha/ObjC++/UnsignedQuery/IRUnsignedQuery.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

typedef UnsignedWrapper<proto::Query> UnsignedQueryCpp;

// TODO: Redesign like in IRKeypair.mm
struct UnsignedQueryImpl {
UnsignedQueryCpp* unsignedQueryCpp;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

typedef UnsignedWrapper<proto::Transaction> UnsignedTransactionCpp;

// TODO: Redesign like in IRKeypair.mm
struct UnsignedTransactionImpl {
UnsignedTransactionCpp* unsignedTransactionCpp;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public class IrohaTransactionPreparation {
}

public func sign(_ unsignedTransaction: IrohaUnsignedTransaction,
with keypair: IrohaKeypair) -> Data {
with keypair: IrohaKeypair) -> Data {
let objectForSigningObjC = unsignedTransaction.getObjectForSigning()

// TODO: Implement better mapping
let keypairObjC: IRKeypair = keypair.getKeypairObjC()

let data = modelProto.signTransaction(objectForSigningObjC, with: keypairObjC)
return data!
}
Expand Down
2 changes: 1 addition & 1 deletion SwiftyIrohaExample/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class ViewController: UIViewController {
.creatorAccountId("admin@test")
.createdTime(Date())
.transactionCounter(1)
.createAccount(withAccountName: "testuser",
.createAccount(withAccountName: "agggggg",
withDomainId: "test",
withPublicKey: keypair.getPublicKey())
.build()
Expand Down

0 comments on commit 0512600

Please sign in to comment.