Skip to content

Commit

Permalink
Merge pull request #163 from ljy0422/Bug-Fix
Browse files Browse the repository at this point in the history
Remove encryption and decryption of data
  • Loading branch information
ljy0422 authored Apr 9, 2024
2 parents d8ad470 + c9fba25 commit 98e613a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 134 deletions.
65 changes: 0 additions & 65 deletions src/main/java/seedu/address/storage/FixedAesUtil.java

This file was deleted.

81 changes: 12 additions & 69 deletions src/main/java/seedu/address/storage/JsonAdaptedPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import com.fasterxml.jackson.annotation.JsonProperty;

import seedu.address.commons.exceptions.IllegalValueException;
//import seedu.address.model.person.Address;
//import seedu.address.model.person.Email;
import seedu.address.model.person.Id;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
Expand All @@ -25,9 +23,9 @@ class JsonAdaptedPerson {

public static final String MISSING_FIELD_MESSAGE_FORMAT = "Person's %s field is missing!";

private String name;
private String id;
private String phone;
private final String name;
private final String id;
private final String phone;
private final String email;
private final String address;
private final List<JsonAdaptedTag> tags = new ArrayList<>();
Expand Down Expand Up @@ -74,25 +72,12 @@ public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("id")
* Converts a given {@code Person} into this class for Jackson use.
*/
public JsonAdaptedPerson(Person source) {
String nameBeforeEncryption = source.getName().fullName;
String hpBeforeEncryption = source.getPhone().value;
//email = source.getEmail().value;
//address = source.getAddress().value;
name = source.getName().fullName;
phone = source.getPhone().value;
id = source.getId().value;
tags.addAll(source.getTags().stream()
.map(JsonAdaptedTag::new)
.collect(Collectors.toList()));
String idBeforeExcryption = id;
try {
String encryptedName = FixedAesUtil.encrypt(nameBeforeEncryption);
String encryptedPhone = FixedAesUtil.encrypt(hpBeforeEncryption);
String encryptedId = FixedAesUtil.encrypt(idBeforeExcryption);
this.name = encryptedName;
this.phone = encryptedPhone;
this.id = encryptedId;
} catch (Exception e) {
e.printStackTrace();
}
email = "test";
address = "test";

Expand All @@ -108,73 +93,31 @@ public Person toModelType() throws IllegalValueException {
for (JsonAdaptedTag tag : tags) {
personTags.add(tag.toModelType());
}
final Set<Tag> modelTags = new HashSet<>(personTags);

if (name == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName()));
}

String decryptedName = "";
try {
decryptedName = FixedAesUtil.decrypt(name);
} catch (Exception e) {
e.printStackTrace();
}

if (!Name.isValidName(decryptedName)) {
if (!Name.isValidName(name)) {
throw new IllegalValueException(Name.MESSAGE_CONSTRAINTS);
}
final Name modelName = new Name(decryptedName);
final Name modelName = new Name(name);

if (phone == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName()));
}

String decryptedPhone = "";
try {
decryptedPhone = FixedAesUtil.decrypt(phone);
} catch (Exception e) {
e.printStackTrace();
}

if (!Phone.isValidPhone(decryptedPhone)) {
if (!Phone.isValidPhone(phone)) {
throw new IllegalValueException(Phone.MESSAGE_CONSTRAINTS);
}
final Phone modelPhone = new Phone(decryptedPhone);

//if (email == null) {
// throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName()));
//}
//if (!Email.isValidEmail(email)) {
// throw new IllegalValueException(Email.MESSAGE_CONSTRAINTS);
//}
//final Email modelEmail = new Email(email);

//if (address == null) {
// throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT,
// Address.class.getSimpleName()));
//}
//if (!Address.isValidAddress(address)) {
// throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS);
//}
//final Address modelAddress = new Address(address);
final Phone modelPhone = new Phone(phone);

if (id == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Id.class.getSimpleName()));
}

String decryptedId = "";
try {
decryptedId = FixedAesUtil.decrypt(id);
} catch (Exception e) {
e.printStackTrace();
}

if (!Id.isValidId(decryptedId)) {
if (!Id.isValidId(id)) {
throw new IllegalValueException(Id.MESSAGE_CONSTRAINTS);
}
final Id modelId = new Id(decryptedId);

final Set<Tag> modelTags = new HashSet<>(personTags);
final Id modelId = new Id(id);

return new Person(modelName, modelId, modelPhone, modelTags);
}
Expand Down

0 comments on commit 98e613a

Please sign in to comment.