Skip to content

Commit

Permalink
some clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhenry committed Mar 19, 2023
1 parent 5be7063 commit ff0d456
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ enum Secrets {

want := `
enum Secrets {
static let key1 = "\({ deobfuscate([0x1a, 0x04, 0x02, 0x08, 0x00, 0x4d, 0x28, 0x1c, 0x17, 0x0f, 0x16], salt: salt) }())"
static let key2 = "\({ deobfuscate([0x13, 0x0f, 0x01, 0x10, 0x07, 0x08, 0x2d, 0x53, 0x16, 0x06, 0x11, 0x17, 0x11, 0x06, 0x41, 0x05, 0x01, 0x16], salt: salt) }())"
static let key3 = "\({ deobfuscate([0x41, 0x53, 0x5f, 0x0e, 0x0b, 0x1e, 0x35, 0x40, 0x57, 0x57, 0x46, 0x4e, 0x49, 0x54, 0x47, 0x5d, 0x56, 0x56, 0x55, 0x6c, 0x41, 0x5c, 0x5b, 0x4b, 0x51, 0x15, 0x1a, 0x05, 0x06, 0x05, 0x45, 0x47, 0x75, 0x33, 0x56, 0x51, 0x41, 0x57, 0x4a, 0x4c, 0x5f, 0x0f, 0x00], salt: salt) }())"
static let key1 = "\(deobfuscate([0x1a, 0x04, 0x02, 0x08, 0x00, 0x4d, 0x28, 0x1c, 0x17, 0x0f, 0x16]))"
static let key2 = "\(deobfuscate([0x13, 0x0f, 0x01, 0x10, 0x07, 0x08, 0x2d, 0x53, 0x16, 0x06, 0x11, 0x17, 0x11, 0x06, 0x41, 0x05, 0x01, 0x16]))"
static let key3 = "\(deobfuscate([0x41, 0x53, 0x5f, 0x0e, 0x0b, 0x1e, 0x35, 0x40, 0x57, 0x57, 0x46, 0x4e, 0x49, 0x54, 0x47, 0x5d, 0x56, 0x56, 0x55, 0x6c, 0x41, 0x5c, 0x5b, 0x4b, 0x51, 0x15, 0x1a, 0x05, 0x06, 0x05, 0x45, 0x47, 0x75, 0x33, 0x56, 0x51, 0x41, 0x57, 0x4a, 0x4c, 0x5f, 0x0f, 0x00]))"
static let key4 = "${IGNORE_ME}"
static let key5 = "${IGNORE_THIS}"
}
// MARK: - Auto generated by envject (https://github.com/michaelhenry/envject)
private let salt: [UInt8] = [0x72, 0x61, 0x6e, 0x64, 0x6f, 0x6d, 0x5f, 0x73, 0x65, 0x63, 0x72, 0x65, 0x74]
private func deobfuscate(_ bytes: [UInt8], salt: [UInt8]) -> String { bytes.enumerated().reduce(into: "") { $0.append(Character(UnicodeScalar($1.element ^ salt[$1.offset % salt.count])))}}`
private func deobfuscate(_ bytes: [UInt8]) -> String { bytes.enumerated().reduce(into: "") { $0.append(Character(.init($1.element ^ salt[$1.offset % salt.count])))}}`

got := ReplaceEnvVariables(configText, "^IGNORE_", &value_encoders.SwiftValueEncoder{Salt: []byte("random_secret")})

Expand Down
4 changes: 2 additions & 2 deletions value_encoders/swift_value_encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ type SwiftValueEncoder struct {

func (v *SwiftValueEncoder) Encode(value string) string {
bytes := obfuscators.Obfuscate(value, v.Salt)
return fmt.Sprintf("\\({ deobfuscate([%v], salt: salt) }())", utils.ConvertBytesToHexString(bytes))
return fmt.Sprintf("\\(deobfuscate([%v]))", utils.ConvertBytesToHexString(bytes))
}

func (v *SwiftValueEncoder) AdditionalCode() string {
return fmt.Sprintf(`
// MARK: - Auto generated by envject (https://github.com/michaelhenry/envject)
private let salt: [UInt8] = [%s]
private func deobfuscate(_ bytes: [UInt8], salt: [UInt8]) -> String { bytes.enumerated().reduce(into: "") { $0.append(Character(UnicodeScalar($1.element ^ salt[$1.offset %% salt.count])))}}`, utils.ConvertBytesToHexString(v.Salt))
private func deobfuscate(_ bytes: [UInt8]) -> String { bytes.enumerated().reduce(into: "") { $0.append(Character(.init($1.element ^ salt[$1.offset %% salt.count])))}}`, utils.ConvertBytesToHexString(v.Salt))
}

func NewSwiftValueEncoder() *SwiftValueEncoder {
Expand Down

0 comments on commit ff0d456

Please sign in to comment.