|
1 | | -use std::io::{Cursor, Write}; |
| 1 | +use std::io::Cursor; |
2 | 2 | use std::path::Path; |
3 | 3 | use std::process::Command; |
4 | 4 | use std::{fs::File, path::PathBuf}; |
5 | 5 |
|
6 | 6 | use anyhow::{anyhow, Context as _, Result}; |
7 | 7 | use clap::{crate_authors, crate_version, Args, Parser}; |
8 | | -use confidential_vm_blobs::{EFI_BOOT_STUB, INIT, KERNEL}; |
| 8 | +use confidential_vm_blobs::{EFI_BOOT_STUB, INIT, KERNEL, maybe_vendored::MaybeVendoredImage}; |
9 | 9 | use tempfile::NamedTempFile; |
10 | 10 |
|
11 | 11 | mod initramfs; |
@@ -86,36 +86,6 @@ struct NonDefaultedArgs { |
86 | 86 | kernel_cmdline: Option<String>, |
87 | 87 | } |
88 | 88 |
|
89 | | -enum MaybeVendoredImage { |
90 | | - External(PathBuf), |
91 | | - /// Unfortunately `ukify` receives its input as a file, so we store fallback blobs in temporary named |
92 | | - /// files before passing them |
93 | | - Vendored(NamedTempFile), |
94 | | -} |
95 | | - |
96 | | -impl MaybeVendoredImage { |
97 | | - fn path(&self) -> &Path { |
98 | | - match self { |
99 | | - MaybeVendoredImage::External(path_buf) => path_buf, |
100 | | - MaybeVendoredImage::Vendored(named_temp_file) => named_temp_file.path(), |
101 | | - } |
102 | | - } |
103 | | - |
104 | | - /// Load a vendored blob to a temp file and create a instance of `Self` from that |
105 | | - fn from_vendored(blob: &[u8]) -> Result<Self> { |
106 | | - let temp_file = NamedTempFile::new() |
107 | | - .and_then(|mut tempfile| tempfile.write_all(blob).map(|_| tempfile)) |
108 | | - .and_then(|mut tempfile| tempfile.flush().map(|_| tempfile)) |
109 | | - .context("failed to write backup kernel image to file")?; |
110 | | - Ok(MaybeVendoredImage::Vendored(temp_file)) |
111 | | - } |
112 | | -} |
113 | | - |
114 | | -impl From<PathBuf> for MaybeVendoredImage { |
115 | | - fn from(value: PathBuf) -> Self { |
116 | | - MaybeVendoredImage::External(value) |
117 | | - } |
118 | | -} |
119 | 89 |
|
120 | 90 | pub fn open_file(path: &Path) -> Result<File> { |
121 | 91 | File::open(path).with_context(|| format!("failed to open file at path {}", path.display())) |
@@ -207,8 +177,7 @@ fn main() -> Result<()> { |
207 | 177 | let application_elf = open_file(&validated_args.non_defaulted_args.application_elf_path)?; |
208 | 178 | let init = Cursor::new(INIT); |
209 | 179 |
|
210 | | - // Unfortunately `aws_nitro_enclaves_image_format::EifBuilder` forces us to have data in |
211 | | - // files. |
| 180 | + // Unfortunately `ukify` forces us to have data in files. |
212 | 181 | let mut initramfs_file = NamedTempFile::new().context("failed to create initramfs file")?; |
213 | 182 | initramfs_file = initramfs::build(application_elf, init, initramfs_file) |
214 | 183 | .context("failed to create initramfs")?; |
|
0 commit comments